I have read some of the related posts about this and didn\'t quite understand. What is happening is it appears that after this access to the database, the database is being left
You should correctly use your connection by using the IDisposable
pattern.
In fact, every classes that implements the IDisposable
interface needs to be call with a using. This ensure that the methods Dispose()
is call, and so the unmanaged resources are being cleared (and you don't end with an open file) :
public static Partner GetOnePartner(string code)
{
Partner partner = new Partner();
string sqlStatement = "SELECT * FROM partners WHERE partner_code = @partner_code";
using(SQLiteConnection connection = GroomwatchDB.GetConnection())
using(SQLiteCommand command = new SQLiteCommand(sqlStatement, connection))
{
command.Parameters.Add(new SQLiteParameter("@partner_code"));
command.Parameters["@partner_code"].Value = code;
connection.Open();
using(SQLiteDataReader reader = command.ExecuteReader(CommandBehavior.SingleRow))
{
if(reader.Read())
{
partner.Code = reader["partner_code"].ToString();
partner.Last_name = reader["last_name"].ToString();
partner.First_name = reader["first_name"].ToString();
partner.Pay_rate = (double)reader["pay_rate"];
partner.Active = reader["active"].ToString();
}
else
{
partner.Code = code;
partner.Last_name = "Not Found";
}
}
}
return partner;
}
References :