Diagnosing an OLEDB exception when Quering Excel 2010 - sql

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?

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.

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();
}

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.

Related

VB.net get first excel sheet name with OleDB Connection

I'm using following code to connect with a Excel file with OleDB:
Connection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Path + ";Extended Properties=Excel 12.0;")
Command = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", Connection)
DataSet = New System.Data.DataSet
Command.Fill(DataSet)
Connection.Close()
I would like to get the name of the first excel sheet and put it in a string variable so I can use it in the SQL command. How can I do this?

need help connecting ms access to vb.net

I need help my program don't the use connection string that i want instead it find the access file on this folder and display error
Could not find file 'C:\Users\user\Documents\Visual Studio 2008\Projects\Patientt\Patientt\bin\Debug\db_hospital.accdb'.
here is my code
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\db_hospital.accdb"
con.Open()
sql = "SELECT * FROM tblPatients"
ds.Clear()
da = New OleDbDataAdapter(sql, con)
da.Fill(ds)
Me.DataGridView1.DataSource = ds.Tables(0)
con.Close()
Put your access file in the debug folder and change the connection string like this
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\db_hospital.accdb"

OLEDB Connection won't connect to Access 2013 database

I am trying to use the OLEDB connection to load my database to my Visual Basic program. However, I am receiving this error:"Could not find installable ISAM."
I am using Microsoft Access Database 2013. As far as I'm aware, 12.0 is the correct version.
This is my code:
Dim con As New OleDb.OleDbConnection
Dim databaseprovider As String
Dim dblocation As String
databaseprovider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
dblocation = "Date source = C:\HotelBookingDatabase.accdb"
con.ConnectionString = databaseprovider & dblocation
con.Open()
MsgBox("open")
con.Close()
MsgBox("closed")
Edit - I have changed "Data source..." to "Data Source..." and installed 2007 Office System drivers, but that hasn't helped my cause.
Edit #2 - Looked at the code above again today. I figured out the problem. Instead of "Data Source", my code has "DATE Source". Oops. Updated code, which works:
Dim con As New OleDb.OleDbConnection
Dim dbprovider As String
Dim dbsource As String
dbprovider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
dbsource = "Data Source = C:\HotelBookingDatabase.accdb;"
con.ConnectionString = dbprovider & dbsource
con.Open()
MsgBox("ok")
con.Close()
MsgBox("bye")
I have sorted out the problem.
I changed my code to this:
Dim con As New OleDbConnection("Provider=MICROSOFT.ACE.OLEDB.12.0; Data Source=C:\HotelBookingDatabase.accdb")
con.Open()
MsgBox("ok")
con.Close()
MsgBox("bye")

OleDb Excel Connection Error "System.Data.OleDb.OleDbException"

I've created a small vb.net application that connects to a an excel sheet on a shared folder.
It works great if i open the excel before using the the application , the issue is when the excel isn't open in the background i get a "System.Data.OleDb.OleDbException" error when trying to open a connection.
I've read a bit about this error and i understand it has something to do with access rights to a local temp library.
So my questions are:
1) Is there a solution?
2) Is this the best connection strategy for my situation where the excel files sit on a shared drive?
Connection code:
skuPath = "C:\path.xlsm"
cn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" + "data source=" + skuPath + ";Extended Properties=Excel 8.0;")
q1 = "select * from [" + year + "$B4:V128]"
da = New System.Data.OleDb.OleDbDataAdapter(q1, cn)
cn.Open()
da.Fill(ds, "Table1")
cn.Close()
dt = ds.Tables(0)
I receive the error on cn.Open().
Got exactly the same problem few weeks ago.
Error is caused by incorrect version of oledb provider, just as Steve suggested.
Try this:
skuPath = "C:\path.xlsm"
cn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;" + "data source=" + skuPath + ";Extended Properties=""Excel 12.0;HDR=Yes""")
q1 = "select * from [" + year + "$B4:V128]"
da = New System.Data.OleDb.OleDbDataAdapter(q1, cn)
cn.Open()
da.Fill(ds, "Table1")
cn.Close()
dt = ds.Tables(0)

vb.net Oracle connection using TNS Name?

I have put my tns connection into the .ora file and am now able to conenct to it using SQL plus and can ping it :tnsping myConn.
I've also added the connection to the ODBC Manager and connecting successfully when tetsing conneciton through the ODBC tool.
now i'm having an issue making a connection to it using vb.net
i've tried the following:
oODBCConnection = New Odbc.OdbcConnection(connStr)
oODBCConnection.Open()
where my connStr is:
Data Source=tns.dev;User Id=MyUser;Password=MyPass;
per: http://www.connectionstrings.com/oracle and http://www.shabdar.org/c-sharp/101-connect-to-oracle-using-asp-net-and-csharp.html
what am i doing wrong? it's telling me i need to specify a driver, how do i do it?
Thank you!
the error i'm getting is:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Did you checked the tnsnames.ora file? Is there any entry for tns.dev?
http://www.mike-devlin.com/oracle/tnsnames_ora.htm
That is not an oracle error - it sounds like you did not create a system dsn. This code looks like it expects a DSN by name of tns.dev.
That said, I would not use odbc if I could help it. You might want to look at Oracle Data Provider for .net
http://www.oracle.com/technetwork/topics/dotnet/index-085163.html
ODBCConnection was incorrect.
solution:
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim myConnection As New OracleConnection(connStr)
myConnection.Open()
I´ve been using the following code in Vb.net
Dim conn As New Odbc.OdbcConnection
Dim cmd As New Odbc.OdbcCommand
Dim drResult As Odbc.OdbcDataReader
Dim connString As String
Dim QuerySQL As String
connString = "Driver={Microsoft ODBC for Oracle};CONNECTSTRING=(DESCRIPTION=(ADDRESS= (PROTOCOL=TCP)(HOST=ORACLEDB01)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE_INSTANCE_NAME)));Uid=john;Pwd=mypassword;"
QuerySQL = "select first_name, last_name from employees where id = 28"
conn.ConnectionString = connString
conn.Open()
cmd.Connection = conn
cmd.CommandText = QuerySQL
drResult = cmd.ExecuteReader()
While drResult.Read
TextBox1.Text = TextBox1.Text & drResult("last_name") & ", " & drResult("first_name") & Environment.Newline
End While
drResult.Close()