Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can a global.asa set two db connections?

Status
Not open for further replies.

bberrios

Programmer
Jun 18, 2002
18
US
I have two databases running off of the same site, and i need to use two global.asa's. since this is not possible, can I put both connections in one file? I did try just merging the two and that did not work, is there another way to do this? bb
 
On the actual asp page that you use.....


set objConn1 = server.createobject("adodb.connection")
objConn1.open application("DB_CONNECTION_STRING")

set objConn2 = server.createobject("adodb.connection")
objConn2.open application("DB_CONNECTION_STRING_2") ---------------------------------------
[turkey] HAPPY THANKSGIVING!!!! [turkey]
mikewolf@tst-us.com
 
I never use the global.asa for database connections. Instead I create a configuration include with seperate database logins. This way I can close the connections right after I pull my data and never have a problem. If your using and access or SQL database this will work. By creating a configuration include I can also use the same file for setting other parameters in my application by using a Virtual connection. I use mostly DSNLess connections and here's a sample.
<%
'---------------Create Common Data Path ---------------------------------------------
Dim DSNless

'Rem this is a DSNless connection for an access db
'
DSNless = &quot;DRIVER={Microsoft Access Driver (*.mdb)};UID=(my user id);PWD=(my password);DBQ=(my hard path to database)D:\website\db\&quot;
'
'------------- Connect to Database one------------------------------------------
'
Function OpenDB1 (ByRef Cn) 'Cn is the reference I pass to the function call


DSN = DSNless & &quot;Database1.mdb&quot;

Set Cn = Server.CreateObject(&quot;ADODB.Connection&quot;)

With Cn
.ConnectionString = DSN
.ConnectionTimeout = 15
.Open
End With

End Function
'
'------------- Connect to Database 2 ------------------------------------------
'
Function OpenDB2 (ByRef Cn)


DSN = DSNless & &quot;Database2.mdb&quot;

Set Cn = Server.CreateObject(&quot;ADODB.Connection&quot;)

With Cn
.ConnectionString = DSN
.ConnectionTimeout = 15
.Open
End With

End Function
'
'---- Repair Quotation Marks -----------------------------------------------------------
'
FUNCTION fixQuotes( theString )
fixQuotes = Replace( theString, &quot;'&quot;, &quot;''&quot; )
END FUNCTION


%>

Remember though that even though I use Cn in both function calls you need to reference them differently on your page. Example :

OpenDB1 Cn1
OpenDB2 Cn2

Hope this helps.
 
nice, I will try the DSNless and see if that works better. It is access databases, both of them...so we will see. bb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top