簡體   English   中英

使用DAO VB.NET打開密碼加密的訪問數據庫

[英]Opening a password encrypted access database using DAO VB.NET

我創建一個這樣的數據庫:

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

如何使用DAO在VB.NET中再次打開此數據庫?

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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM