【问题标题】:Opening a password encrypted access database using DAO VB.NET使用 DAO VB.NET 打开密码加密访问数据库
【发布时间】:2011-02-10 05:29:01
【问题描述】:

我创建一个这样的数据库:

Sub Main()

        Dim wrkDefault As Workspace
        Dim dbE As DBEngine
        Dim dbs As Database

        'Get default Workspace.
        dbE = New DBEngine
        wrkDefault = dbE.Workspaces(0)

        'Set the database filename
        Dim DBFilename As String
        DBFilename = "c:\mydb.mdb"

        'Make sure there isn't already a file with the same name of
        'the new database file.
        If Dir(DBFilename) <> "" Then
            MsgBox("File already exists!")
            Exit Sub
        End If

        'Create a new encrypted database with the specified
        'collating order.
        'lock database with the password 'hello'
        dbs = wrkDefault.CreateDatabase(DBFilename, _
              LanguageConstants.dbLangGeneral & ";pwd=hello;", DatabaseTypeEnum.dbEncrypt)

        dbs.Close()

    End Sub

如何在 VB.NET 中使用 DAO 再次打开这个数据库?

【问题讨论】:

    标签: database vb.net passwords dao encryption


    【解决方案1】:
    Dim cn As New ADODB.Connection
    cn.Provider = "Microsoft Jet 4.0 OLE DB Provider"
    cn.ConnectionString = "Data Source=c:\db1.mdb"
    cn.Properties("Jet OLEDB:Database Password") = "mypwd"
    cn.Open
    

    对于 DAO,连接字符串很可能看起来像这样:

    ODBC;DSN=DSNname;DATABASE=DBname;UID=SQLUser;PWD=SQLpassword;
    

    或者像这样:

    Driver={Microsoft Access Driver (*.mdb)};" & _
             "DBQ=C:\...\NWind.mdb;" & _
             "UID=admin;PWD=password;"
    

    对于第一个字符串,您必须使用控制面板/管理工具/ODBC 源创建一个数据源名称 (DSN) 文件。第二个字符串不需要 DSN 连接。现在您知道他们为什么发明了 ADO.NET。

    【讨论】:

    • 1.您必须为 ADODB 包含哪些引用和命名空间? 2. 有没有办法使用 DBEngine.Workspaces(0) 的 OpenDatabase() 方法?
    • 1.使用 Visual Studio 中添加引用对话框的 COM 选项卡添加对 Microsoft ActiveX 数据对象 2.8 库的引用。
    • 2.不,那是一个 DAO 对象。您可以尝试添加对 Microsoft DAO 3.6 对象库的引用并使用 DAO。这里有一些示例代码:dotnet247.com/247reference/msgs/18/90914.aspx
    • 无论如何,DBEngine 接口的 OpenDatabase() 方法的第四个参数是一个连接字符串,它的结构可能类似于其中一个包含密码的字符串:carlprothman.net/Default.aspx?tabid=90#ODBCDriverForAccess
    • 我试过 OpenDatabase(DBFilename, False, False, "MS Access;pwd=hello;") 但还不够。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多