Global connection

abcd

New member
Joined
Jun 21, 2003
Messages
1
Any body please tell me how to declare the connection object public /global in asp.net and how to call the object in forms.

Thanks in advance
 
You have to declare your object in global.asax

Code:
<object id="MyConnection" class="System.Data.SqlClient.SqlConnection" runat="server" scope="Application"></object>

Than you can use it in following way:

Code:
Dim moConn As System.Data.SqlClient.SqlConnection
moConn = CType(Application.StaticObjects.Item("MyConnection"), System.Data.SqlClient.SqlConnection)

BTW: It is VERY BAD idea having Connection object as global object. Because of connection pooling it is much better to create, use and destroy (close) connection to database as quickly as possible.
 
Back
Top