T
tshad
I have a windows service program that seems to once in a while will not
release a file.
When I am trying to move the file (in the same program) I will get a file in
use and the file will not be moved.
If I go to a Windows Explorer, I can't delete it there either. I have to
stop the service to delete it.
But the only place I open and read it is in a try/catch where I close the
connect in the finally clause.
What would cause it to stay open?
***************************************************
try
{
if (Path.GetExtension(strFile).ToUpper() == ".XLS")
{
mstrConnectionXLS = string.Format(mstrConnectionXLS,
strFile);
connection = new OleDbConnection(mstrConnectionXLS);
connection.Open();
DataTable dt =
connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dt == null)
{
return null;
}
....
}
catch (Exception exc)
{
Logging.WriteToLog(AppSettings.LogFilePath,
String.Format("Exception filling dataset: {0}",
exc.Message));
// Move Zip file to Exception Folder
}
finally
{
if (connection != null)
connection.Close();
}
********************************************************
Thanks,
Tom
release a file.
When I am trying to move the file (in the same program) I will get a file in
use and the file will not be moved.
If I go to a Windows Explorer, I can't delete it there either. I have to
stop the service to delete it.
But the only place I open and read it is in a try/catch where I close the
connect in the finally clause.
What would cause it to stay open?
***************************************************
try
{
if (Path.GetExtension(strFile).ToUpper() == ".XLS")
{
mstrConnectionXLS = string.Format(mstrConnectionXLS,
strFile);
connection = new OleDbConnection(mstrConnectionXLS);
connection.Open();
DataTable dt =
connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dt == null)
{
return null;
}
....
}
catch (Exception exc)
{
Logging.WriteToLog(AppSettings.LogFilePath,
String.Format("Exception filling dataset: {0}",
exc.Message));
// Move Zip file to Exception Folder
}
finally
{
if (connection != null)
connection.Close();
}
********************************************************
Thanks,
Tom