c# - Best practice? open and close multi connections, or one large open connection for ado.net -


I am using ADO.Net for some database connectivity and I was just hoping that I should use it correctly Was doing from. I am opening and closing multiple connections for each stored procedure. Or would I just wrap it in an open connection (less resources on the database)? Thank you, and if anything is weird or something that I'm doing better, thank me!

Example: But I have 6 of them like ...

 using  (SqlConnection conn = new SqlConnection (ConnectionString )) {SqlCommand cmd = new SqlCommand ("spSelect AllTrip", Kon); Cmd.CommandType = CommandType.StoredProcedure; Conn.Open (); DdlTripTypeA.DataSource = cmd.ExecuteReader (); DdlTripTypeA.DataTextField = "TripType"; DdlTripTypeA.DataValueField = "TripTypeAID"; DdlTripTypeA.DataBind (); } (SqlConnection conn = New SqlConnection (connection string)) {SqlCommand cmd = new SqlCommand ("spSelect AllTripB", conn); Cmd.CommandType = CommandType.StoredProcedure; Conn.Open (); DdlTripTypeB.DataSource = cmd.ExecuteReader (); DdlTripTypeB.DataTextField = "TripType"; DdlTripTypeB.DataValueField = "TripTypeBID"; DdlTripTypeB.DataBind (); } 

.net has connection pooling that is already managed for you, so You do not need to worry about reusing the connections like you with the old ASP, I always remain versatile many quick calls, so that the whole time is open because it is not open at all times, usually for calls is used to.

Now if you are going to call 6 calls continuously, then this can mean opening and reusing one. But besides that I say, stay with what you are doing.

The only thing you want to see is a connection manager, so that you can not make connection objects on the Net. And again but there is nothing to do with DB connections, just create the object.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -