Keeping UID and PWD out of an ADO connection string in an ODBC DSN-less Database and a DAO cached connection?

前端 未结 1 1960
眼角桃花
眼角桃花 2021-01-27 16:07

I have used Ben Clothier\'s suggestion from his Office Blog Power Tip (http://blogs.office.com/2011/04/08/power-tip-improve-the-security-of-database-connections/) to create a DS

相关标签:
1条回答
  • 2021-01-27 16:33

    Although ACCESS has some weak points regarding security, you can do few things to minimize the risks. One of them would be compile the DB to ACCDE. This way VBA is compiled and not visible.

    You can create a public function that returns a string

    Public Function GET_CONNECTION_STRING() as STRING
    ' construct your connection string here with server name and password
        GET_CONNECTION_STRING = "DRIVER={" & Driver & "};PORT=" & mPort & ";DATABASE=" & mDatabase & ";SERVER={" & mServer & "};UID=" & mUser & ";PWD={" & mPassword & "};"
    End Function
    

    then create an AutoExe macro that runs when the application is opened. in your AutoExe perform refreshing links to your linked tables. something similar to what you have.

    For Each tdf In db.TableDefs
       If tdf.connect <> vbNullString Then
           tdf.connect = GET_CONNECTION_STRING & ";TABLE=" & tdf.name
           tdf.RefreshLink
        End If
    Next tdf
    

    you can do the same for existing pass through queries:

    For Each myQuerydef In MyDB.QueryDefs
        If Left(myQuerydef.connect, 4) = "ODBC" Then
            myQuerydef.connect = "ODBC;" & GET_CONNECTION_STRING
            myQuerydef.Close
        End If
       Next
    

    in addition you can have some other public functions to get current logged in username. something like

    public function getCrruserID() as int
       'check your public variable crr_user_id if its empty redirect to login
       if nz(crr_user_id,0) = 0 then
         'go to login and save the user id after successful login
       else
          getCrruserID = crr_user_id
       end if
    end function
    

    use simple DAO to execute sql code like

    dim db as DAO.Database
    set db = currentdb
    dim rs as Dao.Recordset
    set rs = db.openrecordset("select something from your linked table")
    

    or

    db.execute "update command", dbfailonerror
    

    to your last question. if you save something in memory it will be destroyed once your application is closed.

    EDIT: if you have more than 50 linked tables it might be not a good idea to refresh them at every startup. Instead you can create a Local table containing your [local_Appversion, isFreshInstall] and some other variables as per your need. Every time your user receives an update the freshInstall will be true and code your App to connect and refresh all tables. (just to make sure client will get uninterrupted connection)

    so in your autoExe code: if its freshInstall then connect and refreshlinks if not just set the connectionString. (usually a splash screen after login to perform this action) After successful connection just update the local isFreshInstall value to false for a quicker start next time.

    you can also have a dedicated menu where user can click and refresh links manually.(in case if the connection get dropped) something like custom menu for access

    if your organisation has a domain you can allow trusted connection using windows login name good luck.

    0 讨论(0)
提交回复
热议问题