Hi there,
I want to encapsulate a db connection into a class and then have a static method within this class that returns an open connection to a database.
I want to know if the connection is closed properly, as the method returns the connection before the closed() command is called. Here is my code:
The method within the class:
How i use this method:
Does the method close the connection properly or shall i create an instance of my data class and call the appropriate method to close it?
Thanks,
James
I want to encapsulate a db connection into a class and then have a static method within this class that returns an open connection to a database.
I want to know if the connection is closed properly, as the method returns the connection before the closed() command is called. Here is my code:
The method within the class:
Code:
public static SqlConnection cnn()
{
try
{
SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
myConn.Open();
return myConn;
myConn.Close();
}
catch
{
return null;
}
}
How i use this method:
Code:
myCommand (sql, dataclass.cnn());
Does the method close the connection properly or shall i create an instance of my data class and call the appropriate method to close it?
Thanks,
James