Search code examples
databasevb.netnetwork-programminglinked-server

In search of a better solution to querying a remote Access database with VB.net


Please tell me there is a better solution to querying a remote Access database!

We are currently using this because thus far we have failed at hooking up a sp_linkedserver. I feel like it's a terrible hack and want to be done with this whole network mapping business once and for all!

    '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:")

Solution

  • I would suggest migrating data onto SQL Server. If you use the linked tables option, you can continue to use the forms, reports and queries in your existing Access db, while still being able to query the data remotely, from as many connections as you can.