Trying to connect to excel 2010 doesn't work - c#

I got this exception:
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
I was trying to connect Excel 2010 files with OleDBConnection. I have windows 7 64bit and office 2010 32 bit.
I have tried to install Microsoft Access Database Engine 2010 Redistributable which suggested from:
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered in the local machine
I also tried this suggestion:
http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/1d5c04c7-157f-4955-a14b-41d912d50a64
Neither one of them works for me. Anyone help?
Here is my code:
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;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);
ds.Tables[0].Rows.Count.Dump();
}
catch (Exception)
{
throw;
}
finally
{
connection.Close();
}

Here's a discussion about this error, please refer to it and let me know whether it is worked for you.
HOW TO FIX
Best Regards
try installing this first: http://www.microsoft.com/download/en/details.aspx?id=13255
try the following method:
NOTE: this DOES work for office 2010 even though it is for 2007 office
download and install this: Download here
in VS click add data source, follow the wizard.

Related

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine in MS office 2013 [duplicate]

This question already has answers here:
'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine
(39 answers)
Closed 7 years ago.
I'm getting the following error
"The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine."
while reading the data from Excel file using OLEDB Data Reader.
Its not working in both 32 and 64 bit machine. Currently my machine having MS office 2013 and VS 2010.
string Connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1;MAXSCANROWS=15;READONLY=FALSE\"";
OleDbConnection con = new OleDbConnection(Connection);
OleDbCommand command = new OleDbCommand();
DataSet ds = new DataSet();
command.CommandText = sql;
command.CommandType = CommandType.Text;
command.Connection = con;
command.Connection.Open();
OleDbDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection);
You need to change the Solution Platform from "Any CPU" to "x86". The steps are given below:
Right click on the Solution File in Solution Explorer
Click on the Configuration Manager.
Click on the Active Platform Drop down, if x86 is already there then select that, else click on New.
Select x86 from the new platform dropdown:
Compile and run your application.
If you are still facing the issue, then try installing Office System Driver. from follow site
http://www.microsoft.com/en-us/download/details.aspx?id=23734
Please refer to the following link for a possible solution:
On 64-bit Windows and 64-bit Office (2010, 2013) environments, there are many reports on this error...
...try using 2007 Office System Driver: Data Connectivity Components

Parsing excel files fails

I have to pull data from an excel file. I was using the below piece of code since last year:
OleDbConnection cnn = new OleDbConnection(#"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + destFile + "; Extended Properties=Excel 12.0;");
string qText = #"select * from [sheetXY$]";
OleDbCommand oconn = new OleDbCommand(qText, cnn);
cnn.Open();
OleDbDataAdapter adp = new OleDbDataAdapter(oconn);
adp.Fill(dt);
cnn.Close();
Since yesterday I get this error message:
I had Office 2010 pro on my machine. According to some google suggestions I installed microsoft database access engine, made no difference. I re-installed whole office, made no difference. Then I installed Office 2013, no go.
What could possibly go wrong from a day to another, and how shall I fix it? I'm out of idea.
Save yourself time and headache and use EPPLUS instead. EPPLUS can be installed via Nuget and you don't have to deal with installing the Office Data access on other machine where your code runs.
You can go for openXML SDK. Which requires no machine level dependency.
http://www.codeproject.com/Articles/371203/Creating-basic-Excel-workbook-with-Open-XML
http://msdn.microsoft.com/en-us/library/office/gg575571(v=office.15).aspx

Visual Studio project Oracle connection works for one but not for other

The following Database connection code is working in one project but not for other.
Both
Reside in the same folder
Accessing the same Oracle.dataaccess dll
I am unable to understand what might have led the other project not connect to oracle DB.
I am out of ideas on how to make this project use the connection strings in the tnsnames.ora.
Any help is appreciated
Code:
string constr = "Data Source=Dev11G;User Id=Username;Password=pwd;";
OracleConnection con = new OracleConnection(constr);
con.Open();
OracleCommand cmd = new OracleCommand("Select * from Table", con);
cmd.CommandType = CommandType.Text;
DataTable dt = new DataTable();
using (OracleDataAdapter da = new OracleDataAdapter())
{
da.SelectCommand = cmd;
da.Fill(dt);
}
Error being Recieved: ORA-12154:TNS:could not resolve the connect identifier specified
Error occuring at: con.Open();
Have you tried using EZCONNECT instead of using TNS Names? TNS Names is convenient on a client (with IDEs, etc), but any time you have to deploy an application, you're dependent on whomever maintains that machine. If they update TNS names, it could potentially interfere with your application.
The connection string can be as simple as:
string conString = String.Format("Direct=true;Data Source={0};Port={1};" +
"Service Name={2};User={3};Password={4};Connection Timeout={5}", ...
If you don't know these values, you can find a machine where it's set up correctly and:
tnsping Dev11G
Thanks for all of your posts.I finally found it.it has to do with the local IIS server settings.The project that is succesfully connecting to Oracle is using visual studio development server...while the other one which is unable to connect is using local IIS server.So I have to grant the IIS access to the tnsnames.ora folder.
This post really helped me...
Oracle ORA-12154 error on local IIS, but not with Visual Studio Development Server

Reading xlsx file in c# using OleDbConnection throws error

I wrote a console application to read the xlsx file in C# using OleDbConnection. It throws the following error
The Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
Below is the code i have written
string connString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Suganya\ColumnReport.xlsx;Extended Properties=Excel 12.0;";
OleDbConnection objConn = new OleDbConnection();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
objConn = new OleDbConnection(connString);
string Query = "SELECT * FROM [Sheet1$]";
OleDbCommand objCmd = new OleDbCommand(Query, objConn);
DataTable Table = new DataTable();
dataAdapter.SelectCommand = objCmd;
dataAdapter.Fill(Table);
I have already performed following things to fix the issue.
I have installed AccessDatabaseEngine.exe (32 bit) and found that ACEOLEDB.dll is present in the following path C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14
Tried referring the ACEOLEDB.dll in the application. But it gave me the following error
A reference to 'ACEOLEDB.DLL' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component
The configuration platform of console application is of 32 Bit
Environment Details
Windows Server 2008 (64 bit)
Visual Studio 2010 ( 32 bit)
MS office is not installed
Checked the following links to fix the issue
1.http://www.codeproject.com/Questions/486549/Theplus-27Microsoft-ACE-Oledb-12-0-27plusproviderp
2.http://www.codeproject.com/Questions/337953/The-Microsoft-ACE-OLEDB-12-0-provider-is-not-regis
Any help is highly appreciated.
You have to install Microsoft Office; Office installation process will copy and register the wished assemblies ('ACEOLEDB.DLL') in the GAC, or you can add the missing assemblies in your bin (application) directory or regsiter them by your self.

The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine

Can someone help me with this error? When I try to open a connection to an mdb, I get "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine" error. How can I correct this?
My code is pretty simple:
class ImportTDB {
private string filename;
private string connectionString;
private int collisions = 0;
public ImportTDB(String filename) {
this.filename = filename;
this.connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename;
}
public void loadCustomerList() {
DataTable dt = new DataTable();
using (OleDbConnection conn = new OleDbConnection(connectionString)) {
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Names", conn);
conn.Open();
adapter.Fill(dt);
conn.Close();
}
Console.WriteLine(dt.ToString());
}
}
That's because there is no Jet driver for 64-bit systems and I suppose you are trying to run this on a x64 bit OS. You need to compile your program to target x86. In the project properties, Build tab, set Platform target to x86.
If you are running your application in a 64 bit OS, Microsoft has now released the 2010 Office System Driver Beta: Data Connectivity Components which is supported both in 32 bit as well as 64 bit OS. So using this driver instead of the traditional Microsoft.Jet.OLEDB.4.0 driver will give us a 64 bit application running on a 64 bit server (that is what we really need).
Though this is in beta, it worked fine for me.
You can download this driver from 2010 Office System Driver Beta: Data Connectivity Components
Thnks

Categories

Resources