2

To query an excel sheet via SQL, I used to use either:

Dim excelConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strPath + ";Extended Properties=""Excel 8.0;IMEX=1;HDR=YES;"""

or

Dim excelConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + strPath + ";Extended Properties=""Excel 12.0;IMEX=1;HDR=YES;"""

Now this worked fine until I installed Office 2010.

Now I get a

Microsoft.Ace.OLEDB.12.0 provider is not registered on this machine exception.

How can I find out the correct connection string/provider?

Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442

3 Answers3

7

I believe for Excel 2010 it is :

Dim excelConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=D:\\MyDocs\\oledb.xlsx;Mode=Share Deny Write;Extended Properties=""HDR=YES;"";Jet OLEDB:Engine Type=37"

This appears to work in my visual studio, I got Excel to generate the query string and it had the extra entry in it.

JDunkerley
  • 12,355
  • 5
  • 41
  • 45
2

I downloaded and installed Office System Driver: Data Connectivity Components as advised above - and the below code worked:

    string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Password=\"\";User ID=Admin;Data Source=d:\\Sample.xlsx;Mode=Share Deny Write;Extended Properties=\"HDR=YES;\";Jet OLEDB:Engine Type=37";

    OleDbConnection connection = new OleDbConnection(connectionString);

    try
    {
        connection.Open();

        OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", connection);
        OleDbDataAdapter adapter = new OleDbDataAdapter();
        adapter.SelectCommand = command;

        DataSet ds = new DataSet();
        adapter.Fill(ds);

        GridView1.DataSource = ds;
        GridView1.DataBind();

    }
    catch (Exception)
    {            
        //throw;
    }
    finally
    {
        connection.Close();
    }
Andrei Drynov
  • 8,362
  • 6
  • 39
  • 39
1

Perhaps you uninstalled the Access Database Engine (ACE) components? They are still available for download from MSDN as 2007 Office System Driver: Data Connectivity Components.

onedaywhen
  • 55,269
  • 12
  • 100
  • 138