I have a file PC.sdfI'm working with. I close the connection and I need to remove it.
I open the connection as follows:
bool OpenConn()
{
try
{
Conn = new SqlCeConnection(String.Format(@"Data Source={0}\{1}", PathI, "PC.SDF"));
Conn.Open();
return true;
}
catch
{
return false;
}
}
I close it like this:
Conn.Close();
Conn.Dispose();
I am trying to remove it like this:
if (File.Exists(@"\myPath\PC.sdf"))
File.Delete(@"\myPath\PC.sdf");
But I get this error: file in use by another process. What could be causing this error and how can I fix it?
source
share