Muss ich die SQLConnection explizit schließen und entsorgen?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Muss ich die SQLConnection explizit schließen und entsorgen?

Post by Anonymous »

SqlDataReader rdr = null;
con = new SqlConnection(objUtilityDAL.ConnectionString);
using (SqlCommand cmd = con.CreateCommand())
{
try
{
if (con.State != ConnectionState.Open)
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(Parameter);
cmd.CommandText = _query;
rdr = cmd.ExecuteReader();
}
catch (Exception ex)
{
throw ex;
}
}
< /code>

In diesem obigen Code wird SQLConnection im verwalteten Code geöffnet. Wird das Verbindungsobjekt daher automatisch entsorgt>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post