Storing database connection in ASP

1100885 pts.
Tags:
ASP
Database
My apologizes but I'm going to get right into my question: In ASP, can I store my database connection in the session object? Or is there a much preferred method? Thanks!

Answer Wiki

Thanks. We'll let you know when a new response is added.
<%
‘ASP classic database connection in a session object
ConnectionString=”Provider=IBMDA400.DataSource.1;Persist Security Info=False;User ID=USUARIO;Password=CLAVE; Data 

Source=SERVIDOR;Protection Level=None;Initial Catalog=CATALOGO;”
on error resume next
set session(“con”) = Server.CreateObject(“ADODB.Connection”)
session(“con”).open(ConnectionString)
if err.number <> 0 then
   mensaje= Err.description
   on error goto 0
else
   on error goto 0
   psq=”SELECT * FROM ARCHIVO”
   set r = Server.CreateObject(“ADODB.recordset”)
   r.Open psq, session(“con”)
   do until r.eof
response.write r(0) & “<br>”
r.movenext
   loop
   r.close
   set r=nothing
end if
%>

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: