|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Managing Database Connections!Just throwing something out to the newsgroup to get a feel for what others are doing. I am noticing that with my current coding practice, every time i want to update a database i generally implement the following pattern. 1) Open db connnection 2) Execute Query 3) Close Db Connection Having written numerous events / methods that require db access, i am getting tired of having to manage the Db connection in each routine; ie create and close a connection like so. //create db connection SqlConnection Cn = new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]); //open db connection Cn.Open(); //close db connection Cn.Close(); Apart from laziness, i have realized when a post back requires a number of actions I am opening & closing the database numerous times, and wonder how efficient it is. How does everyone else handle their db work. Does anyone else have a method that allows you to reuse an existing Db Connection? A singleton class ect??? I am about to add a DAL to an existing 1.1 project....how would ya'll manage your db connections in their. Would love any sample code and / or tutorials ? Input appreciated. Adam "AJ" <A*@discussions.microsoft.com> wrote in message DAL.news:38D06517-14B0-47BF-A087-BF2A607F0D84@microsoft.com... > How does everyone else handle their db work. > Does anyone else have a method that allows you to reuse an existing Db That's what connection pooling is for. You should always close your database > Connection? connection object as soon as possible - so long as the connection string which was used to open the connection is the same, ADO.NET will reuse it from the connection pool for you by default... > I am about to add a DAL to an existing 1.1 project....how would ya'll Email me privately and I'll happily send you my v1.1 DAL for SQL Server, > manage > your db connections in their. > > Would love any sample code and / or tutorials ? together with a class which simulates nullable datatypes - not necessary for v2...
Other interesting topics
Master Page prevents using style sheets?
Problem with RaiseCallbackEvent wildcard mapping Delayed Code Execution? I/O stream performance Security exception with impersonate true for a webservice Help debugging...where do I look? making sure page loads Overture/Yahoo & Google PPC referral tracking Is it possible to have more than one login control in a website? |
|||||||||||||||||||||||