पहला प्रश्न:
कहो मेरे पास है
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
string storedProc = "GetData";
SqlCommand command = new SqlCommand(storedProc, connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@EmployeeID", employeeID));
return (byte[])command.ExecuteScalar();
}
क्या कनेक्शन बंद हो गया? क्योंकि तकनीकी }रूप से हम returnउससे पहले कभी भी अंतिम रूप में नहीं पहुंचते हैं।
दूसरा सवाल:
इस बार मेरे पास है:
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
int employeeID = findEmployeeID();
connection.Open();
SqlCommand command = new SqlCommand("UpdateEmployeeTable", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@EmployeeID", employeeID));
command.CommandTimeout = 5;
command.ExecuteNonQuery();
}
}
catch (Exception) { /*Handle error*/ }
अब, tryहम कहते हैं कि कहीं हम एक त्रुटि प्राप्त करते हैं और यह पकड़ा जाता है। क्या अब भी कनेक्शन बंद है? क्योंकि फिर से, हम बाकी कोड को छोड़ देते tryहैं और सीधे catchस्टेटमेंट पर जाते हैं।
मैं कैसे usingकाम करता है में बहुत रैखिक सोच रहा हूँ ? Dispose()जब हम usingस्कोप छोड़ते हैं तो क्या केवल कॉल किया जाता है?