How to open a connection to a database 
Author Message
 How to open a connection to a database

    Hello.

    I want to open a connection to a database, and close this one at the end
of the session. How Can I do this?

    I suppose that i have to assign to a session var but I do not know how.



Sat, 07 Jun 2003 02:47:44 GMT  
 How to open a connection to a database

Put Something like this into your global.asa.

Sub Session_OnStart

    Session("BWA_ConnectionString") =
"DSN=Whatever;SERVER=127.0.0.1;DATABASE=MyDB;"

    Session("BWA_ConnectionTimeout") = 60

    Session("BWA_CommandTimeout") = 90

    Session("BWA_RuntimeUserName") = "SA"

    Session("BWA_RuntimePassword") = ""

end sub

then on your web pages:

    Set BWA = Server.CreateObject("ADODB.Connection")

    BWA.ConnectionTimeout = Session("BWA_ConnectionTimeout")

    BWA.CommandTimeout = Session("BWA_CommandTimeout")

    BWA.Open Session("BWA_ConnectionString"),
Session("BWA_RuntimeUserName"), Session("BWA_RuntimePassword")

to open the connection. However this connection will close when the script
on the page completes

processing. This text placed at the beginning of every page( or in an
include file) works pretty well.

hope this helps,

Tony O


Quote:
>     Hello.

>     I want to open a connection to a database, and close this one at the
end
> of the session. How Can I do this?

>     I suppose that i have to assign to a session var but I do not know
how.



Sat, 07 Jun 2003 14:36:15 GMT  
 How to open a connection to a database
An answer and a warning.

You can assign a connection to a session variable using the following code:

Dim cn

Set cn = Server.CreateObject("ADODB.Connection")
cn.Open ....

Set Session("DBConnection") = cn

The warning:  Don't do this.  This is not good style.  It uses up memory on the
web server.  It increases the database seats that you must purchase, since a
license is in use for as long as the session is active.  By default, this is
about twenty minutes.  It is much better technique to create the connection in
every web page in which it is required.  If you are really concerned about the
time required to do this, look at the pooling functionality offered by Microsoft
Transaction Server.  When pooling is used, the connections are kept open in a
pool.  Then when they are required, a connection object is provided to the ASP
page.  When finished, the connection is returned to the pool.  While you are
still maintaining open connections, at least they are available to everyone who
might need them, so the total number of connections is lower.

Bruce Johnson
TAG Consulting

Quote:
-----Original Message-----

    Hello.

    I want to open a connection to a database, and close this one at the end
of the session. How Can I do this?

    I suppose that i have to assign to a session var but I do not know how.

.



Sat, 07 Jun 2003 08:32:41 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. MSDTC Error when opening a connection to a database

2. MSDTC Error when opening a connection to a database

3. database connection remain open if opened via recordset

4. ADO Database connection open or closed?

5. Open Connection to Database?

6. Opening an Access database with ADO connection and VBScript

7. Opening two database connections

8. Problem opening ADO connection to database on a CDROM

9. When to open ADO Database Connection

10. App opening 3 connections to SQL Server database

11. Runtime error opening a database connection

12. Copy database with open connection

 

 
Powered by phpBB® Forum Software