public DataSet FillContact(string mcid)
{
DataSet ds = new DataSet();
OdbcDataAdapter da = new OdbcDataAdapter();
query = "Select formid,FIELDID,NOID,TEXT from contacts where formid='"+ mcid +"'";
OdbcCommand cmdc = new OdbcCommand(query);
using (OdbcConnection connc = new OdbcConnection(connstring))
{
cmdc.Connection = connc;
connc.Open();
da.SelectCommand = cmdc;
da.Fill(ds, "Contacts");
return ds;
}
}
this is the function i use to return dataset
now what i m preplexed about is
i am using odbc connection by using keyword
my 2 questions are
will using automatically close the connection when it's scoped out?(Query normally executed)
will using still automatically closes the connection when it encounters the problem in any of the code before return ds;
Loading
Kirtan PatelPosted Dec 4, 2009, 7:32 AM
if my answer helps you then check "Do you like this answer" check box please :)
Answer to 1st Question
-----------------------------
Yes, Friend it will Close the Connection Automatically When its Out of Scope .
Answer to 2nd Question
------------------------------
as you told that if program generates the error in between the using Block then program will terminate the Execution . hence no case of Disposing the connection object as it disposed automatically by Terminating program.
if you handle the Error/Exception using Try catch block then it will fully execute the code and after executing the block it will close the connection object .