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!

Help, conn string in global .asa

Status
Not open for further replies.

DREAMaker

Programmer
Oct 7, 2000
7
IT
1)I want add a Session_OnEnd event in global.asa in order to write in the UserTable of my DB the date of the last session of every user...
I set a variable in global.asa in this way...

Sub Session_OnEnd
FINE=now()
End Sub

Now I have to write the value of FINE in the record in my DB with

Update UsersTable set LastSess=FINE
where User='"&Session("User")&"'"

(I think this work fine)
...But I'm not sure about the sintax of the conn string (a DSNless conn string)in global.asa...

2)I'd like set a conn string (DSNless conn) to DB in global.asa so I can call it in a page every time I need to connect to DB... is this possible and how?
Thanks :)
[sig][/sig]
 
try putting something like this in the sub:

set conn=server.createObject("ADODB.Connection")
conn.open "dbname"
conn.execute("UPDATE Users...")

For a DSNless connection you need to substitute "dbname" with something like:
"PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=dbpath;USER ID=id;PASSWORD=pwd;"
(This would be MSAccess. There's a different format for SQL server, Oracle etc.)

People usually warn against running an application-level database connection unless you have a low-hit site because all the requests that want to access the connection object have to wait in line for the one connection if there's a lot of activity. [sig]<p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br> [/sig]
 
Thanks for your reply Will :)
Just a question again...

I know how to set a DSN conn to DB.
But what I ignore is how to set it in global.asa and call it in my page...

Can you help me in do this?

(Please forgive my not very good english...)
[sig][/sig]
 
Assuming this is what you are looking for:

1. Conn string in global.asa and use later in page
in global.asa
session(&quot;Conn&quot;) = &quot;yourConnectionString...as Will also mentioned&quot;
in your page to open database
<% Conn.open(session(&quot;Conn&quot;))%>


2. To read the value of FINE(session variable) in your page
<%cmdSQL = &quot;select * from tbl where fld = '&quot; & Session(&quot;FINE&quot;) & &quot;'&quot;%>

HTH
Nanda
 
Sorry, I misunderstood your second question. I thought you wanted the connection object to be opened in the global.asa but you're referring just to the connection string.

Nanda has it right except that I don't see why it would have to be a session variable since the connection string is just a static string, identical for all users. The purpose for making it global would be that you don't want to bother retyping over and over (I assume). So you could also write:

in global.asa:
----------------------------
Application(&quot;connStr&quot;) = &quot;yourconnectionstring&quot;


in asp pages:
----------------------------
set conn = server.createObject(&quot;ADODB.Connection&quot;)
conn.Open Application(&quot;connStr&quot;)
etc.



By the way, your english is OK
[sig]<p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br> [/sig]
 
Well Will, (nice words' game!) find people like you and Nanda is always very kind... thank you for your help!
I hope to be as useful as you've had been to me every time I could be...
Bye! [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top