is this enough to free the resources? RRS feed

  • Question

  • Hi,

    Imam using this to close the connection but I feel after many entries that the system will be slow and it will take a very long to run the process.. so is this enough:

    if (sql_reader != null) sql_reader.Close();
    if (sql_connection != null) { if (sql_connection.State == ConnectionState.Open) sql_connection.Close(); }

    Saturday, December 7, 2013 10:31 AM


  • While Close might do you should be using Dispose method (rather than or just).

    i.e. even better in combination with using keyword which calls Dispose in a try/catch block for you.

    using (SqlConnection conn = new SqlConnection())

    Miha Markic [MVP C#] http://blog.rthand.com

    Saturday, December 7, 2013 10:47 AM