SQL AUTH. PERSISTENT CONNECTION

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello. Is there a way that I can put a username and password in VBA code to
authenticate to a SQL database and have the connection persist throughout the
entire time Access is open? I am using Access 2003. Thank you.
 
Are you using and Access MDB or a an Access project (ADP)? Access projects
allow you to set it and forget it without having to use code at all which is
handy.

Otherwise I'm not sure that you can for mdb files. Maybe what you could do
as a work around is set up a global ADODB.connection variable and open it by
calling a functino in the autoexec macro. Then just reference the connection
variable when ever you want to make a call to the db. I've never done it so
I can't be certain but it should work I reckon.

Chuck this in a module and a RunCode action into an AutoExec macro with the
argument "SetConnection()" and see how you get on. The just use cnn when
ever you need to reference the connection. Have a crack.

-----------------------------------

Const CNNString = "Provider=Microsoft.Access.OLEDB.10.0;Persist Security
Info=True;Data Source=11.11.1.1\Fresh;User ID=SA;Password=PWord;Initial
Catalog=Fresh;Data Provider=SQLOLEDB.1"

Global cnn as ADODB.Connection

Function SetConnection()

Set cnn = New ADODB.Connection
cnn.ConnectionString= CNNString
cnn.Open

end function
 
Back
Top