Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
Hello guys,
 
There are 2 connection strings below and I tried both..However, I got same error.
 
How can I solve it?
 
string conString = string.Format(@"Provider=Microsoft.ACE.SQLOLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0", Server.MapPath(dosya));
 
string conString = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;HDR=Yes;IMEX=1"
 

An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLEDB;'.
Posted 9-Oct-12 22:27pm
Comments
hemantrautela at 14-Oct-12 1:49am
   
if you trying with excel 2007 or 2010 then there provider should be installed. Then it works else you have to be use old mechanism as I given in answer below
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use this resource for all your connection string needs,
 
The Connection String Reference [^]
 
Excel Connection Strings [^]
 
Hope it helps.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Have you just tried with actual filename instead of {0}
 
strConnect = _T("Provider=Microsoft.Jet.OLEDB.4.0;"
        "Data Source=C:\\DatabasePath\\DBSpreadSheet.xls;"
        "Extended Properties=\"\"Excel 8.0;HDR=Yes;\"\";");
  Permalink  
Comments
haluk_78 at 10-Oct-12 5:21am
   
Could you tell me what the meaning of "_T"?
Santhosh Kumar J at 10-Oct-12 6:12am
   
its nothing, you can write strconnect=string.Format(("Provider=Microsoft.Jet.OLEDB.4.0;"
"Data Source=C:\\DatabasePath\\DBSpreadSheet.xls;"
"Extended Properties=\"\"Excel 8.0;HDR=Yes;\"\";");
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

//1. EXCEL TO .NET
// How Retrieve Data From Excel to Gridview in C#.NET , ASP.NET
//Database Connection String for Excel 2003 for C#.NET, ASP.NET HELP 
//
using System.Data.OleDb;
 protected void btn_showst_Click()
    {
        OleDbConnection con;
        try
        {
            string file = "book";
            string fn = "Sheet1";
            string fname2 = "[" + fn + "$]";
            con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\" + file + ".xls;Extended Properties=Excel 8.0;"); 
            con.Open();
            OleDbCommand cmd = new OleDbCommand("select * from " + fname2 + "", con);
            OleDbDataReader dr;
            dr = cmd.ExecuteReader();
            GridView1.DataSource = dr;
            GridView1.DataBind();
            con.Close();
        }
        catch (Exception ex)
        {
            Label2.Text = ex.Message;
        }
    }
 

///2. MS-ACCESS  TO .NET
//Connection String for ms-access to C#.NET, ASP.NET 
// How Retrieve Data From Access to Gridview 

 
using System.Data.OleDb;
protected void btn_showst_Click()
    {
    OleDbConnection con;
 
    con = new OleDbConnection("Microsoft.Jet.OLEDB.4.0"      connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\databasename.mdb");
 
   // Here Access database should be in App_Data Folder..

 
  con.Open();
  OleDbCommand cmd = new OleDbCommand("select * from  tablename", con);
  OleDbDataReader dr;
  dr = cmd.ExecuteReader();
  GridView1.DataSource = dr;
  GridView1.DataBind();
  con.Close();
}
 
//3. Sql Server To .NET
// Connection String For Sql Server to C#.NET, ASP.NET
// How retrieve Data From Sql Server to Gridview

 
using System.Data.SqlClient;
 

protected void btn_showst_Click()
    {
 
SqlConnection con = new SqlConnection("Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\Database.mdf; Integrated Security=True;User Instance=True");
 // Here Sql Database file should be in App_Data Folder.. 

// or
con.Open();
SqlCommand com = new SqlCommand("select * from " + tablename + " ", con);
SqlDataReader dr = com.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
 con.Close();
}
 

//////   Two Type of SqlConnection String First for sql file and Second for sql server 
SqlConnection con = new SqlConnection("Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\Database.mdf; Integrated Security=True;User Instance=True");
 
// In below Server name or ip address is come there , Initial Catalog for Database name; user id -password // is sql user id and password by defaul sql user is 'sa' and password you should be set it 
//
SqlConnection con = new SqlConnection( "Server=127.0.0.1;Initial Catalog=Database;User ID=sa;Password=123456" ); 
Thank You
http://hemantrautela.blogspot.com/2012/09/database-connection-in-cnet-aspnet-with.html[^]
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 328
1 Sergey Alexandrovich Kryukov 295
2 Gihan Liyanage 292
3 ClimerChinna 222
4 Abhinav S 187
0 Sergey Alexandrovich Kryukov 8,213
1 OriginalGriff 7,089
2 CPallini 2,598
3 Richard MacCutchan 1,925
4 Abhinav S 1,778


Advertise | Privacy | Mobile
Web02 | 2.8.140826.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100