Reading xlsx file in c# using OleDbConnection throws error - c#

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.

Related

Unable to use Oracle Data Access after publishing to azure

I installed 64-bit ODAC 12c Release 4 (12.1.0.2.4) for Windows x6464-bit on my machine. and used this to connect to a remote oracle db. this worked well when I deployed to a normal IIS. But when is published to azure as an Azure cloud service (my project is a WCF service). I get the following error
System.DllNotFoundException: Unable to load DLL 'OraOps12.dll'
Now I have no idea why this is happening. This is the code I'm using to connect to db
OracleConnection con = new OracleConnection();
con.ConnectionString = "User Id=Usr;Password=*****;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx.xxx.xxx.xxx)(PORT=xxxx)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
con.Open();
OracleCommand comm = new OracleCommand();
string comandtext = "Select * from COR_EMPL_MASTER where EMPL_CODE='" + u.EMPL_EMPL_Code + "'";
DataSet ds = new DataSet();
OracleDataAdapter da = new OracleDataAdapter(comandtext, con);
da.Fill(ds);
This is because there is no OraOps12.dll file on azure.
You can throw OraOps12.dll into /Bin folder in your project and add Reference for it by virsual studio. After that you can publish your project to Azure cloud service.
finally fixed it
Hey use this link to http://alderprogs.blogspot.com/2009/04/deploying-odpnet-with-oracle-instant.html. Firstly use the Xcopy version of the drivers downloaded from here http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html add reference to Oracle.dataaccess.dll from this after which right click on it and select properties and in the properties set "local copy=true"
then what you have to do is right-click on the project select "Add Existing Item". Add all the required dlls like oci.dll,OraOps12.dll etc. Now in the properties of these of these dlls set "Copy to output directory = Copy if Newer" and publish to azure it will work.

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

Trying to connect to excel 2010 doesn't work

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.

Categories

Resources