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
 
Usually you would set the application variable for your connection in the global.asa - you can set as many variables as you would like. I don't believe that you are actually making the connection in the global file.

global.asa

application("connStr1") = ...
application("connStr2") = ....


yourPages.asp
set objConn1 = server.createobject("adodb.connection")
objConn1.open application("connStr1")

set objConn2 = server.createobject("adodb.connection")
objConn1.open application("connStr2") -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
I tried putting two on one page and that didn't work...both pages ignore the file. bb
 
You mean that you set a variable in the global.asa file and cannot access it from the pages? This is very strange. Can you post the global.asa and a page where you are accessing the application variable? -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
I am only setting the session and such. Below is what I have, but I want to use it for two databases...it works currnently as is..

<SCRIPT LANGUAGE=&quot;VBScript&quot; RUNAT=&quot;Server&quot;>

Sub Application_OnStart()
'Application(&quot;DB_CONNECTION_STRING&quot;) = &quot;DSN=HIPPA&quot;
'Application(&quot;DB_CONNECTION_LOGIN&quot;) = &quot;hippa&quot;
'Application(&quot;DB_CONNECTION_PASSWORD&quot;) = &quot;hippa&quot;
End Sub

Sub Application_OnEnd()

End Sub

Sub Session_onStart()
'Set Session(&quot;DB_CONNECTION&quot;) = Server.CreateObject(&quot;ADODB.Connection&quot;)
'Session(&quot;DB_CONNECTION&quot;).Open Application(&quot;DB_CONNECTION_STRING&quot;),Application(&quot;DB_CONNECTION_LOGIN&quot;),Application(&quot;DB_CONNECTION_PASSWORD&quot;)

'initialize user login variables
session(&quot;flagLogin&quot;) = -1
session(&quot;Authorized&quot;) = &quot;false&quot;
session(&quot;LoginError&quot;) = &quot;&quot;
session(&quot;UserRole&quot;) = &quot;none&quot;
session(&quot;Email&quot;) = &quot;none&quot;
session(&quot;UserName&quot;) = &quot;none&quot;
session(&quot;Password&quot;) = &quot;none&quot;
session(&quot;UserId&quot;) = &quot;-1&quot;
session.Timeout = 20
End Sub

Sub Session_onEnd()
'Session(&quot;DB_CONNECTION&quot;).Close
'Set Session(&quot;DB_CONNECTION&quot;) = Nothing
End Sub
</SCRIPT> bb
 
Absolutly do not store database connections in application or session, this violates the principal of connection pooling.

-pete
 
You need to change you variable names for the second connection....


Sub Application_OnStart()
Application(&quot;DB_CONNECTION_STRING&quot;) = &quot;DSN=HIPPA&quot;
Application(&quot;DB_CONNECTION_LOGIN&quot;) = &quot;hippa&quot;
Application(&quot;DB_CONNECTION_PASSWORD&quot;) = &quot;hippa&quot;
Application(&quot;DB_CONNECTION_STRING_2&quot;) = &quot;DSN=newDSN&quot;
Application(&quot;DB_CONNECTION_LOGIN_2&quot;) = &quot;newUser&quot;
Application(&quot;DB_CONNECTION_PASSWORD_2&quot;) = &quot;newPassword&quot;
End Sub


It would be even easier if you wrote the complete connection string in one vairable per connection
Sub Application_OnStart()
Application(&quot;DB_CONNECTION_STRING&quot;) = &quot;DSN=HIPPA;User Id=hippa;Password=hippa&quot;
Application(&quot;DB_CONNECTION_STRING_2&quot;) = &quot;DSN=newDSN;User Id=newUser;Password=newPassword&quot;
End Sub

You may also want to use more descriptive names than (&quot;DB_CONNECTION_STRING&quot;) & (&quot;DB_CONNECTION_STRING2&quot;) -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
ok, it's the string2 i didn't didn't rename...i left it as string, because the rest i had changed...thanks..i will try it and let you know how it works... bb
 
palbano & onpnt,

He is just storing the string used to create the connection in application variables. He only uses them to create and open connections when they are necessary. That shouldn't cause any problems, should it? -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 

Sub Session_onStart()
'Set Session(&quot;DB_CONNECTION&quot;) = Server.CreateObject(&quot;ADODB.Connection&quot;)
 
Oops, I was just looking at the application variables - you guys are right about that! No session connections bberios, create, open, use and close them on the page that is called... -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
Oh, crap... I'm not a VBer... Those lines are commented out yes?

Sorry.. I should know better than try to read VB code.

-pete
 
Yes, they are commented out. They are just making sure you know not to uncomment them..... ---------------------------------------
[turkey] HAPPY THANKSGIVING!!!! [turkey]
mikewolf@tst-us.com
 
>> you sincerly sounded nerve-recked there palbano

na... just tryin to humorize... none of this stuff is going to cost lives so it's all good. :)

-pete
 
ok, so I tried the method:

You need to change you variable names for the second connection....


Sub Application_OnStart()
Application(&quot;DB_CONNECTION_STRING&quot;) = &quot;DSN=HIPPA&quot;
Application(&quot;DB_CONNECTION_LOGIN&quot;) = &quot;hippa&quot;
Application(&quot;DB_CONNECTION_PASSWORD&quot;) = &quot;hippa&quot;
Application(&quot;DB_CONNECTION_STRING_2&quot;) = &quot;DSN=newDSN&quot;
Application(&quot;DB_CONNECTION_LOGIN_2&quot;) = &quot;newUser&quot;
Application(&quot;DB_CONNECTION_PASSWORD_2&quot;) = &quot;newPassword&quot;
End Sub

This still only allowed for one connection. I also uncommented the:
'Set Session(&quot;DB_CONNECTION&quot;) = Server.CreateObject(&quot;ADODB.Connection&quot;)

and it made no difference...any other suggestions...thanks so much!

bb
 
You have defined two connections there. In order to use them all you need to do is choose which connection settings to use when you open your recordset or connection object. Since you won't be opening the connection in your global.asa file you will need to handle this in your web page.
As long as your doing that I can't see any reason that this would fail. Perhaps you should post the portion of the code where you are actually using the two differant connections.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
This space has nothing in it, it's all ni your imagination
 
Here is the code I am using...i do set the sessoin on the pages in a different include...so i should leave the session part out, right?



Sub Application_OnStart()
Application(&quot;DB_CONNECTION_STRING&quot;) = &quot;DSN=HIPPA&quot;
Application(&quot;DB_CONNECTION_LOGIN&quot;) = &quot;hippa&quot;
Application(&quot;DB_CONNECTION_PASSWORD&quot;) = &quot;hippa&quot;
Application(&quot;DB_CONNECTION_STRING_2&quot;) = &quot;DSN=DOD&quot;
Application(&quot;DB_CONNECTION_LOGIN_2&quot;) = &quot;&quot;
Application(&quot;DB_CONNECTION_PASSWORD_2&quot;) = &quot;&quot;
End Sub

Sub Application_OnEnd()

End Sub

Sub Session_onStart()
'Set Session(&quot;DB_CONNECTION&quot;) = Server.CreateObject(&quot;ADODB.Connection&quot;)
'Session(&quot;DB_CONNECTION&quot;).Open Application(&quot;DB_CONNECTION_STRING&quot;),Application(&quot;DB_CONNECTION_LOGIN&quot;),Application(&quot;DB_CONNECTION_PASSWORD&quot;)
'Application(&quot;DB_CONNECTION_STRING_2&quot;),Application(&quot;DB_CONNECTION_LOGIN_2&quot;),Application(&quot;DB_CONNECTION_PASSWORD_2&quot;)

'initialize user login variables
session(&quot;flagLogin&quot;) = -1
session(&quot;Authorized&quot;) = &quot;false&quot;
session(&quot;LoginError&quot;) = &quot;&quot;
session(&quot;UserRole&quot;) = &quot;none&quot;
session(&quot;Email&quot;) = &quot;none&quot;
session(&quot;UserName&quot;) = &quot;none&quot;
session(&quot;Password&quot;) = &quot;none&quot;
session(&quot;UserId&quot;) = &quot;-1&quot;
session.Timeout = 20
End Sub

Sub Session_onEnd()
'Session(&quot;DB_CONNECTION&quot;).Close
'Set Session(&quot;DB_CONNECTION&quot;) = Nothing
End Sub








bb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top