|
|
Need to make connection within application not using Application.GetNewConnection
Posted: 20 Sep 07 8:31 AM
|
I need to run a script as an agent and it is failing whenever 'Application....' is called. I would like to create the connection without hardcoding the actual DB name or hardcoding passwords so I can move from Dev to production without editing the scripts or putting passwords in plain text in the code. Is this possible and if so what is the best method to do this? I have used a connection string created from a .udl file before, but this required some hard coding if I recall.. Thanks |
|
|
|
Re: Need to make connection within application not using Application.GetNewConnection
Posted: 20 Sep 07 11:19 AM
|
First create the UDL file by creating a new text file and rename it to something like MyConnection.UDL. Then double-click it and configure the connection details.
To create a new connection object and set the connection for it, you just need a few short lines of code:
Dim conn Set conn = CreateObject("ADODB.Connection") conn.Open "File Name=C:\MyConnection.udl"
That is it. Make sense? |
|
|
|
Re: Need to make connection within application not using Application.GetNewConnection
Posted: 20 Sep 07 11:24 AM
|
You could drop that in an include script like this to make it a bit more reusable:
Function GetNewConnection(ByVal UdlFile) Set GetNewConnection = CreateObject("ADODB.Connection") GetNewConnection.Open "File Name=" & UdlFile End Function
Now you can easily use it like this:
Set rs = GetNewConnection("C:\MyConnection.udl").Execute("select * from sometable") While Not rs.EOF '... Wend
Or any way you'd use the built in Application.GetNewConnection, just pass the UDL file to it. |
|
|
| |
| |
| |
|