Below is my code:
using (pgsqlConnection conn = new pgsqlConnection(connStr))
{
} //automatically Dispose()
public class v2Connection:IDisposable
{
public void Dispose()
{
//close the connection and release resources
}
}
This is what I have written so far in my Connection class (v2Connection). It is giving error on pgsqlConnection and it is obvious that at present neither I have a class with this name nor an Interface.
I want to add two function: Open and Close. I am not following where should I call Open() and Close()? If I create an interface with the name: IConnection with two methods:
int Open();
int Close();
How to use this interface in the above code?
You could have a wrapper for your connection :
With MyConnectionWrapper :
and in the constructor of your class
and in the Dispose function :