ADODB连接 - 错误:未找到数据源名称且未指定默认驱动程序

时间:2014-12-16 05:44:53

标签: c# ms-access oledb ado

过去使用ODBC连接到Access DB时从未遇到任何问题。现在我尝试使用ADO / OLEDB进行连接,我收到此错误(DSNless连接):

System.Runtime.InteropServices.COMException:[Microsoft] [ODBC驱动程序管理器]未找到数据源名称且未指定默认驱动程序。

我不再使用ODBC。正如我所说,我正在使用ADO / OLEDB。这是我的代码:

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

我已经查看了Google和本网站关于MS Access此错误的几乎所有内容。我已经尝试将我的项目更改回32位(x86)。似乎没什么用。

有人有什么想法吗?

更新 我需要一个ADODB连接,因为我正在使用需要ADODB连接的ADOX。

var cat = new Catalog();
// this line below will bomb for ODBC or OLEDB
cat.ActiveConnection = con;

3 个答案:

答案 0 :(得分:0)

尝试进行OLEDB连接。还请提一下输出。

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

您需要在建立连接时提供特定的驱动程序信息。请按下一个代码。

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

答案 1 :(得分:0)

您必须安装需要建立连接的OLEDB驱动程序:

连接字符串:

<add name="ConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source d:\\test.mdb;Persist Security Info=False;" />

驱动程序可以从以下链接安装: http://www.microsoft.com/en-in/download/details.aspx?id=13255

答案 2 :(得分:0)

我只是在解决这个问题,我找到了一个对我有用的奇怪解决方案:

        // 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);