Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

You have to declare your object in global.asax

 

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

 

Than you can use it in following way:

 

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.

A man and a dog have an average of three legs.

Beaware of Statistics.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...