The 'Microsoft.ACE.OLEDB.14.0' provider is not registered error on Sharepoint Visual Studio WebPart while uploading a excel file

StackOverflow https://stackoverflow.com/questions/20271120

Domanda

I am creating a sharepoint webpart solution where i need to upload a excel file

Here is my code:

string tempFilename = "";

SPSecurity.RunWithElevatedPrivileges(delegate
{

  tempFilename = System.IO.Path.GetTempFileName();
  flUpload.SaveAs(tempFilename);

  string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=\"Excel 8.0;HDR=No;IMEX=1\";", tempFilename);
  connectionString = @"Provider=Microsoft.ACE.OLEDB.14.0;Data Source="+tempFilename+@";ExtendedProperties=""Excel 12.0;HDR=YES;""";

  var adapter = new OleDbDataAdapter("SELECT * FROM [Failed Trades$]", connectionString);
  var ds = new DataSet();

 adapter.Fill(ds, "anyNameHere");

 DataTable data = ds.Tables["anyNameHere"];

The Connection String generated is:

 Provider=Microsoft.ACE.OLEDB.14.0;Data Source=C:\Windows\ServiceProfiles
\NetworkService\AppData\Local\Temp\Demo1.xls;
 ExtendedProperties="Excel 12.0;HDR=YES;"

I had looked hundrededs of solutions but none of them is workimg.

Here are few solutions what i tried:

  1. Installed setups from microsoft (64 bit)
  2. Change the application pool with 32 bit enabled but that caused my pool to stopped again and again

I checked my DSN as well enter image description here

È stato utile?

Soluzione

Change the version number of the OLEDB driver in your connection string from:

Microsoft.ACE.OLEDB.14.0

to

Microsoft.ACE.OLEDB.12.0

This should work presuming you've installed the Microsoft Access Database Engine 2010 Redistributable.

Altri suggerimenti

You can try this:

  1. In ODBC Data source administration click in "User DNS", and click "Excel files", and "Configuration..."

like here

  1. In the next window: "ODBC Microsoft Excel Setup", click in "Version" and see the list of drives.

like here

  1. Put the correct version in your connection String. like:

    Microsoft.ACE.OLEDB.12.0 or Microsoft.ACE.OLEDB.14.0

You can select all:

public string tables(string strFileName)
{
    DataTable dt = null;
    try
    {
        recarrega = false;
        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.15.0;Data Source=" + strFileName + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\";");
        conn.Open();
        dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
        conn.Close();
    }
    catch (Exception a)
    {
        MessageBox.Show("15 - " + a.Message);
        try
        {
            recarrega = false;
            OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.14.0;Data Source=" + strFileName + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\";");
            conn.Open();
            dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
            conn.Close();
        }
        catch (Exception b)
        {
            MessageBox.Show("14 - " + b.Message);
            try
            {
                recarrega = false;
                OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.13.0;Data Source=" + strFileName + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\";");
                conn.Open();
                dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                conn.Close();
            }
            catch (Exception c)
            {
                MessageBox.Show("13 - " + c.Message);
                try
                {
                    recarrega = false;
                    OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strFileName + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\";");
                    conn.Open();
                    dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                    conn.Close();
                }
                catch (Exception d)
                {
                    MessageBox.Show("12 - " + d.Message);
                }
            }
        }
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top