Jump to content

is this right way for sqlserver connection in asp.net c#


sansat6699

Recommended Posts

i have my connection string placed in appsetting tag in web.config file and i am accesing it in class as

sqlconnection con1=new sqlconnection (configurationsetting.appsettings["myconnection"]);
now problem is that is it ok that if i created instance of class on another pagae like
classreport abc= new Classreport ;
then i am accessing that instance with connection created in itlike
abc.con1.open();
it's a multiuser application so it is okey to open connection from class in page , or recomend me better approch connection with sqlserver
Link to comment
Share on other sites

My understanding is that it doesn't matter where you have your SqlConnection object - you can put it in a stand-alone data connection class, you can have it in your data object classes, or you can do it right on the page. What matters, however, is that you use the same connection string to open each of your connections (so .NET can use Connection Pooling) and that you close those connections as soon as you are done using them (so that you don't tie those connections up when other processes attempt to use them).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...