0

请告诉我查询远程 Access 数据库有更好的解决方案!

我们目前正在使用它,因为到目前为止我们未能连接 sp_linkedserver。我觉得这是一个可怕的 hack,我想一劳永逸地完成整个网络映射业务!

    'This is for access 2007
    'DataBase on Local Machine
    '*************************************************************************************************
    'Before a conneciton is made this code sends the credentials to the remote path.
    Dim objNetwork As Object
    objNetwork = Microsoft.VisualBasic.CreateObject("WScript.Network")
    'this line below deletes the drive if there is one so that a correct mapped drive can be created
    'objNetwork.RemoveNetworkDrive("W:")
    Dim DriveLetter = "W:" ' *** This drive needs to be deleted after it is created see the end of this sub for deletion
    Dim RemotePath = "\\volume10\pickles\toads\rocks\sheepy\almostTodb\behindTheScenes"
    Dim UserID = "sysama01\starUser"
    Dim UserPWD = "secretPass"
    objNetwork.MapNetworkDrive(DriveLetter, RemotePath, False, UserID, UserPWD)
    'Syntax()
    '****.MapNetworkDrive(strLocalDrive, strRemoteShare, [persistent], [strUser], [strPassword])
    'Options:
    'strLocalDrive  : The drive letter (e.g. L:)
    'strRemoteShare : The UNC path to the remote drive \\MyServer\MyPrinter
    '(String value)
    'persistent     : True/False - store the mapping persistently in the users profile
    'default = false
    'strUser        :  The user name. (Optional)
    'strPassword    :  The password. (Optional)
    ' Location for code http://ss64.com/vb/drivemap.html
    '*************************************************************************************************
    'DataBase on Network Drive
    objConn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=W:\SuperDeliciousFoodDB.accdb;Jet OLEDB:Database Password=databasePasswordHere")
    'DataBase on Network Drive
    objConn.Open()
    objCmd = New OleDbCommand("SELECT * from pancakeTable, objConn)

    objReader = objCmd.ExecuteReader
...
'Do more codestuffs here
objNetwork.RemoveNetworkDrive("W:")
4

1 回答 1

0

我建议将数据迁移到 SQL Server 上。如果您使用链接表选项,您可以继续使用现有 Access 数据库中的表单、报表和查询,同时仍然能够从尽可能多的连接远程查询数据。

于 2012-06-14T03:27:31.030 回答