This method has to access a database file and perform a simple query:
private static DataTable QueryStuff(string connectionString, string[] types)
{
string queryTypes = "('" + string.Join("', '", types) + "')";
DataTable dtResults = new DataTable();
try
{
using (FbConnection myConnection1 = new FbConnection(connectionString))
{
myConnection1.Open();
FbTransaction fbTransaction = myConnection1.BeginTransaction();
FbCommand fbCommand = new FbCommand();
fbCommand = new FbCommand()
{
CommandText = "SELECT * FROM TABLE WHERE TYPE IN " + queryTypes + ";",
CommandType = CommandType.Text,
Connection = myConnection1,
Transaction = fbTransaction
};
FbDataReader dr = fbCommand.ExecuteReader();
dtResults.Load(dr);
dr.Close();
fbTransaction.Commit();
}
}
catch (Exception ex)
{
MessageBox.Show("Erro: " + ex.Message);
}
return dtResults;
}
Afterwards, the program has to delete the database file, like this:
if (File.Exists(filePath))
File.Delete(filePath);
Except, it can't, for the file is in use by 'another process'.
The program itself has created the file, and I am sure that the file is not being used in any other process.
Is there a better way to dispose this connection?