This is a relatively simple question but I want to make sure I am doing this the right way.
What is the best practice for connecting to a database? This is how I am currently doing it and I want to make sure this is more or less following best practice.
private static SQLiteConnection conn;
public static SQLiteConnection Conn
{
get
{
try
{
if (conn == null)
conn = new SQLiteConnection(fullName);
if (conn.State != ConnectionState.Open)
{
conn.ConnectionString = connectionString;
conn.Open();
}
}
catch (Exception Excp)
{
DataErrorLogger.WriteError(Excp, "");
}
return conn;
}
}
When I actually use the connection I am doing this.
using (SQLiteConnection conn = new SQLiteConnection(SQLiteConn.Conn))
{}
Thanks!