2011-05-02 7 views

답변

1

using 문이나 try/finally 중 하나를 사용하여 제대로 연결을 닫으시겠습니까?

using (MySqlConnection conn = new MySqlConnection("string")) 
{ 
    conn.Open(); 
    // your code here 
} 

또는

MySqlConnection conn = null; 
try 
{ 
    conn = new MySqlConnection("string"); 
    conn.Open(); 
    // your code here 
} 
finally 
{ 
    if (conn != null) { conn.Close(); } 
} 
+0

그래, 난 finally 블록에서 열려있는 모든 연결을 종료하고,하지만 오류는 받고있어 정확한 오류가 무엇 아직 – aditya

+0

입니까? 당신은 Command, DataReader 등의 객체를 모두 처분하고 있습니까? – jessehouwing

관련 문제