I never had problems connecting to Access DBs in the past using ODBC. Now I am trying to connect using ADO/OLEDB and I am getting this error (DSNless connection):
System.Runtime.InteropServices.COMException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.
I am no longer using ODBC. As I said I am using ADO/OLEDB. Here's my code:
var conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\test.mdb";
// I've also tried the one below, same error
// var conString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:\\test.mdb";
var con = new ADODB.Connection( conString );
// bombs here
con.Open();
I've looked at almost everything Google and this site has regarding this error with MS Access. I've tried changing my projects back to 32-bit (x86). Nothing seems to work.
Anyone have any ideas?
UPDATE: I need an ADODB connection because I am using ADOX which requires an ADODB connection.
var cat = new Catalog();
// this line below will bomb for ODBC or OLEDB
cat.ActiveConnection = con;
Try making OLEDB connection. Also please mention the output .
Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connetionString As String
Dim cnn As OleDbConnection
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=yourdatabasename.mdb;"
cnn = New OleDbConnection(connetionString)
Try
cnn.Open()
MsgBox("Connection Open ! ")
cnn.Close()
Catch ex As Exception
MsgBox("Can not open connection ! ")
End Try
End Sub
End Class
You need to provide the specific Driver Info While making the connection .Follow the Next code .
Imports System.Data.Odbc
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connetionString As String
Dim cnn As OdbcConnection
connetionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=yourdatabasename.mdb;"
cnn = New OdbcConnection(connetionString)
Try
cnn.Open()
MsgBox("Connection Open ! ")
cnn.Close()
Catch ex As Exception
MsgBox("Can not open connection ! ")
End Try
End Sub
End Class
You have to install OLEDB drivers which required to make connection:
Connection string:
<add name="ConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source d:\\\\test.mdb;Persist Security Info=False;" />
Drivers can install from below link: http://www.microsoft.com/en-in/download/details.aspx?id=13255
I was just wrestling with this problem and I found an odd solution that worked for me:
// NOTE: this way doesn't work. It throws an error:
// System.RuntimeInteropServices.COMException (0x80004005): [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified at ADODB.Connection.Open
//_connection = new Connection(_connectionString);
//_connection.Open();
// This way *does* work.
_connection = new Connection();
_connection.Open(_connectionString, null, null, 0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.