且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何以编程方式从Access数据库中删除已知密码?

更新时间:2022-12-30 23:31:52

以编程方式更改密码的方法详细

The way to change the password programmatically is detailed here.

本质上,需要执行以下操作:

Essentially, one needs to do the following:

  1. 使用ADO.NET打开与数据库的连接
  2. 在数据库上执行一条alter语句,将其密码设置为NULL:

  1. Open a connection to the database using ADO.NET
  2. Execute an alter statement on the database setting it's password to NULL as so:

ALTER DATABASE PASSWORD [您的密码] NULL;

ALTER DATABASE PASSWORD [Your Password] NULL;

  • 释放连接

  • Dispose the connection

    取自源代码的示例代码:

    Sample code taken from the source:

    Private Function CreateDBPassword(ByVal Password As String, _
        ByVal Path As String) As Boolean
    Dim objConn as ADODB.Connection
    Dim strAlterPassword as String
    On Error GoTo CreateDBPassword_Err
    ' Create the SQL string to initialize a database password.
    strAlterPassword = "ALTER DATABASE PASSWORD [Your Password] NULL;"
    
    ' Open the unsecured database.
    Set objConn = New ADODB.Connection
    With objConn
        .Mode = adModeShareExclusive
        .Open "Provider=Microsoft.Jet.OLEDB.4.0;Data " & _
            "Source=[Your Path];" 
    
     ' Execute the SQL statement to secure the database.
     .Execute (strAlterPassword)
    End With
    
    ' Clean up objects.
    objConn.Close
    Set objConn = Nothing
    
    ' Return true if successful.
    CreateDBPassword = True
    
    CreateDBPassword_Err:
    Msgbox Err.Number & ":" & Err.Description
    CreateDBPassword = False 
    End Function