tshad replied to Peter Duniho
09-Feb-10 07:57 PM

This is not much better but I put the part in that fills the dataset.
This has been working fine for months without much change. The only
difference seems to be with this file that actaully has about 6000 rows vs.
about 200. Sometimes it releases and other times it does not.
So you are saying that my finally is really useless except to close the
connection since I am not actually closing the file?
***************************************************
string mstrConnectionXLS = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source={0};Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1\"";
string mstrConnectionXLSX = "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source={0};Extended Properties=\"Excel 12.0;HDR=NO;IMEX=1\"";
string strSQL = "SELECT * FROM [{0}$]";
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;
}
foreach (DataRow row in dt.Rows)
{
if (!row["TABLE_NAME"].ToString().EndsWith("$"))
{
// Check to see if Table_Name has single quote at end
if(!row["TABLE_NAME"].ToString().EndsWith("$'"))
continue;
}
tableName = row["TABLE_NAME"].ToString().Replace("$", "");
da = new OleDbDataAdapter(String.Format(strSQL, Regex.Replace(tableName,
da.Fill(ds, tableName);
}
}
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