在同一位置链接后端密码保护的访问数据库

Posted

技术标签:

【中文标题】在同一位置链接后端密码保护的访问数据库【英文标题】:link back-end password protected access database within same location 【发布时间】:2018-11-30 06:41:15 【问题描述】:

我正在使用下面的代码将我的银行端数据库链接到前端。它可以正常工作,而无需在后端数据库上设置密码。如何将相同的代码与受密码保护的后端文件一起使用。注意:以下代码来自 [*** question][1]

 [1]: https://***.com/questions/3315306/how-can-a-relative-path-specify-a-linked-table-in-access-2007


    Private Sub Form_Load()
    Dim strOldConnect As String
    Dim strNewConnect As String
    Dim intSlashLoc As Integer
    Dim intEqualLoc As Integer

    Dim strConnect As String
    Dim strFile As String
    Dim strCurrentPath As String

    strCurrentPath = CurrentProject.path

    Dim tblDef As TableDef
    Dim tblPrp As Property

    For Each tblDef In CurrentDb.TableDefs
    Debug.Print tblDef.Name
    If tblDef.Connect & "." <> "." Then

        strOldConnect = tblDef.Connect
        intEqualLoc = InStr(1, strOldConnect, "=", vbTextCompare)
        strConnect = Left(strOldConnect, intEqualLoc)
        intSlashLoc = InStrRev(strOldConnect, "\", -1, vbTextCompare)
        strFile = Right(strOldConnect, Len(strOldConnect) - intSlashLoc)
        strNewConnect = strConnect & strCurrentPath & "\" & strFile

        tblDef.Connect = strNewConnect
        tblDef.RefreshLink
    End If

    Next tblDef
    End Sub

【问题讨论】:

【参考方案1】:

Access Microsoft ACE OLEDB 12.0 的整个连接字符串是:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb; Jet OLEDB:Database Password=MyDbPassword; 

请参阅此链接以获取参考https://www.connectionstrings.com/access/

在你的情况下,这将是诀窍:

tblDef.Connect = "PWD=" & MyPassword & ";DATABASE=" & YourDatabasePath

【讨论】:

运行时错误“3170”:找不到可安装的 ISAM。【参考方案2】:

我自己找到了解决方法,想分享一下,谢谢。

Public Function DBconnect()
Dim Password As String
Dim FileName As String
Dim CurrentConnection As String
Dim AccessConnect As String
Dim NewConnection As String
Dim CurrentPath As String
Dim CurrentLocationEnd As Integer

AccessConnect = "MS Access;PWD=password;DATABASE="
Password = "password"
CurrentPath = CurrentProject.Path

Dim tblDef As TableDef
Dim tblPrp As Property

For Each tblDef In CurrentDb.TableDefs
Debug.Print tblDef.Name
If tblDef.Connect & "." <> "." Then
CurrentConnection = tblDef.Connect
CurrentLocationEnd = InStrRev(CurrentConnection, "\", -1, vbTextCompare)
FileName = Right(CurrentConnection, Len(CurrentConnection) - CurrentLocationEnd)
NewConnection = AccessConnect & CurrentPath & "\" & FileName
tblDef.Connect = NewConnection
tblDef.RefreshLink
End If
Next tblDef
End Function

【讨论】:

以上是关于在同一位置链接后端密码保护的访问数据库的主要内容,如果未能解决你的问题,请参考以下文章

如何使用CORS保护REST API?

MS Access 无法链接到加密的后端数据库

存储密码的位置 - 第 3 方 API

在前端和后端保护路由[关闭]

访问同一类的另一个对象的受保护属性的方法

密码重置后端功能