Link to home
Start Free TrialLog in
Avatar of karlhsc
karlhscFlag for Afghanistan

asked on

Provider is not registered error

Hello.  I am developing a C#.NET application that allows the user to upload an Excel 2007 file.  My .NET application then parses through the Excel file and ultimately inserts some data from the Excel file into a MSSQL database.

Currently, my application successfully allows for the upload of the Excel file to occur, but it is having trouble reading from it.  The code is below.

string connectionString = @"Provider=Microsoft.Jet.OLEDB.12.0; Data Source=\\ttuhsc.edu\shares\fiscal\general services\copfs1\aspnet\elb\DO_NOT_DELETE.xlsx;Extended Properties=""Excel 12.0;HDR=YES;""";

DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");

DbDataAdapter adapter = factory.CreateDataAdapter();

DbCommand selectCommand = factory.CreateCommand();

selectCommand.CommandText = "SELECT Last Name, First Name,Banner ID FROM [getreport$]";
               
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = connectionString;
                
selectCommand.Connection = connection;

adapter.SelectCommand = selectCommand;
                
DataSet NewExcelFile = new DataSet();
                
adapter.Fill(NewExcelFile);

Open in new window


When the program flow reaches the last line in this code block, I get a "The 'Microsoft.Jet.OleDb.12.0' provider is not registered on the local machine." error.  My local PC is running a 32-bit version of Windows XP Pro and I have Office 2007 installed.

Thank you in advance.
Avatar of Blacklord_76
Blacklord_76

I think you need to correct your connection string.
Instead of "Jet" it would be "ACE".


http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/b70a8fe1-4253-4043-a9c0-98b4e369821c
Avatar of karlhsc

ASKER

I changed "Jet" to "ACE" and got the following error:

The 'Microsoft.ACE.OleDb.12.0' provider is not registered on the local machine.

Here is what I changed it to:



string connectionString = @"Provider=Microsoft.ACE.OleDb.12.0; data source=\\ttuhsc.edu\shares\fiscal\general services\copfs1\aspnet\elb\DO_NOT_DELETE.xlsx; Extended Properties=Excel 12.0;";

Open in new window

Avatar of karlhsc

ASKER

Also, I am wondering if "local machine" (from error message) refers to my PC or the server.  I am guessing that it has to be the server, as the error occurs while the application's code is running on the server.
1) Local machine is  a machine where you're running the code. If you're running it on the server, then you need to ensure that the server has Office 2007 Installed. OleDb provider is installed along with the office 2007.
2) In case if you have office installed, I'd propose to check (on the same machine that you have OleDB provider installed) what providers you actually have. It's little bit deep in the registry, but you could could paste the following code into a console output and run it. It should be a line "Microsoft.ACE.OleDb.12.0" or a similar one. Please use this line in your connection string. If you have nothing like that you'd probably need to reinstall Office (it think it worth to wait until going with it)

class Program
    {
        static void Main(string[] args)
        {
            RegistryKey clsIDs = Registry.ClassesRoot.OpenSubKey("CLSID");
            var subkeyNames = clsIDs.GetSubKeyNames();
            foreach (var subkeyName in subkeyNames)
            {
                var subkey = clsIDs.OpenSubKey(subkeyName);

                if (null != subkey.GetValue("OLEDB_SERVICES"))
                {// this is 
                    var oledDBprovider = subkey.OpenSubKey("OLE DB Provider");
                    if (oledDBprovider != null)
                    {
                        Console.WriteLine(subkey.GetValue(""));
                    }
                }
            }
            Console.ReadKey();
        }
    }

Open in new window

Avatar of karlhsc

ASKER

Lord - thank you for your reply.  My application is an ASP.NET application that runs on a server, so I suspect the problem may be that the server does not have Office 2007 components installed (I found this: http://www.microsoft.com/downloads/en/details.aspx?familyid=7554f536-8c28-4598-9b72-ef94e038c891&displaylang=en ).

My assumption is that because this is an ASP.NET app, running on a server, it doesn't matter what I have installed locally on my PC (other than a compatible browser).  I do have Office 2007 installed, however, already along with IE 7.  Both are fully patched.

Any idea if there is a way to determine what version of OLEDB (I guess I need v12.0?) is currently available on the server?  I'm an old PHP developer, so the equivalent of phpinfo() would work great, if there was one in ASP.NET.  I have turned tracing on, but that doesn't appear to list information about OLEDB.
Avatar of karlhsc

ASKER

One thing I should mention is that I do not control the server that hosts my application, so I can't for example remote desktop in to it.
ASKER CERTIFIED SOLUTION
Avatar of Blacklord_76
Blacklord_76

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial