0
    Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\itweb\Documents\Visual Studio 2010\WebSites\notitiae\databases\notitiae.accdb"
    Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)

    Dim queryString As String = "SELECT [tblCounties].* FROM [tblCounties]"
    Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
    dbCommand.CommandText = queryString
    dbCommand.Connection = dbConnection

    Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
    dataAdapter.SelectCommand = dbCommand
    Dim DSCounties As System.Data.DataSet = New System.Data.DataSet
    dataAdapter.Fill(DSCounties)

好的。所以我使用上面的代码连接到一个access 2007 DB。现在我必须添加一个指向具有用户级保护的数据库的链接表。研究向我展示了如何将用户名和密码添加到连接字符串。Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;数据源=C:\Users\itweb\Documents\Visual Studio 2010\WebSites\notitiae\databases\notitiae.accdb;用户名=user;密码=pwd ;"

我还了解到我需要添加对工作组文件“V:\DATABASE\WORKDIR\diodb.mdw”的引用。我的问题是所有在线引用工作组文件的信息都使用 ADODB 连接而不是我的 OleDb 连接和 jet 4 而不是 ACE 12。添加工作组文件的语法是什么?我尝试将 ADODB 对象添加到我的 Visual Studio 项目中,但 VS 不会添加 ActiveX Data Objects 2.5 的引用。这就是我使用 OleDB 的原因。

4

2 回答 2

0

以下 Excel VBA 代码有效,证明ACE.OLEDB仍然可以打开.mdb具有用户级安全性的文件。请注意,.mdw文件的属性仍然使用Jet OLEDB:前缀。

Sub ulsTest()
Dim con As ADODB.Connection, rst As ADODB.Recordset
Set con = New ADODB.Connection
con.Open _
        "Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source=C:\Users\Public\ulsTest\ulsTest.mdb;" & _
        "Jet OLEDB:System Database=C:\Users\Public\ulsTest\Security.mdw;" & _
        "User ID=Gord;" & _
        "Password=obfuscated;"
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM ulsTable", con
Debug.Print rst(0).Value
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing
End Sub
于 2013-05-03T14:35:06.503 回答
0
    Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=C:\Users\itweb\Documents\Visual Studio 2012\Projects\Notitiae_project\Notitiae_project\App_Data\notitiae.accdb;" & "Jet OLEDB:System Database=V:\DATABASE\WORKDIR\diodb.mdw;" & "User ID=ITWeb;" & "Password=Mike1;"
    Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
    Dim queryString As String = "SELECT [tblCounties].* FROM [tblCounties]"
    Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
    dbCommand.CommandText = queryString
    dbCommand.Connection = dbConnection

    Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
    dataAdapter.SelectCommand = dbCommand
    Dim DSCounties As System.Data.DataSet = New System.Data.DataSet
    dataAdapter.Fill(DSCounties)
于 2013-05-06T12:39:16.103 回答