Asp.net 间歇性问题-OleDbConnection.Open()引发System.Data.OleDb.OLEDBEException:未指定错误
我们组织中的一个生产应用程序使用Excel 2003文件通过web应用程序处理用户提交的数据。此应用程序大部分时间工作可靠。最近,当调用OleDbConnection.Open()方法时,应用程序开始间歇性抛出“System.Data.OleDb.OleDbException:Unspecified error”。该错误将继续,直到应用程序池被回收,此时所有功能都会按预期运行。Windows应用程序事件日志中未捕获任何错误 ASP.NET web应用程序托管在Windows Server 2003 32位计算机上WSS 3.0中的web部件中。该应用程序旨在防止任何并发问题。系统功能id是唯一可以访问临时文件存储的帐户,并且内置了一些机制,以确保在使用唯一命名约定和上载跟踪子系统进行处理期间,文件不会被其他上载覆盖 如有任何见解,将不胜感激 我们使用以下代码从Excel 2003文件检索数据:Asp.net 间歇性问题-OleDbConnection.Open()引发System.Data.OleDb.OLEDBEException:未指定错误,asp.net,excel,ado.net,oledb,Asp.net,Excel,Ado.net,Oledb,我们组织中的一个生产应用程序使用Excel 2003文件通过web应用程序处理用户提交的数据。此应用程序大部分时间工作可靠。最近,当调用OleDbConnection.Open()方法时,应用程序开始间歇性抛出“System.Data.OleDb.OleDbException:Unspecified error”。该错误将继续,直到应用程序池被回收,此时所有功能都会按预期运行。Windows应用程序事件日志中未捕获任何错误 ASP.NET web应用程序托管在Windows Server 200
public static DataTable GetWorksheetData(string filePath)
{
OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder { DataSource = filePath };
builder.Provider = "Microsoft.Jet.OLEDB.4.0";
builder["Extended Properties"] = "Excel 8.0;IMEX=1;HDR=YES";
DataTable table = new DataTable();
try
{
// Creates an OleDbConnection for the excel file
using (OleDbConnection connection = new OleDbConnection(builder.ConnectionString))
{
connection.Open();
string sheetName = GetWorksheet(connection, "Template");
if (!string.IsNullOrEmpty(sheetName))
{
using (OleDbCommand command = connection.CreateCommand())
{
try
{
command.CommandText = string.Format("SELECT * FROM [{0}]", sheetName);
using (OleDbDataAdapter adapter = new OleDbDataAdapter(command))
using (DataSet dataSet = new DataSet())
{
adapter.Fill(dataSet);
table = dataSet.Tables[0];
}
}
finally
{
connection.Close();
}
}
}
else
{
throw new InvalidWorksheetException();
}
}
}
catch (Exception ex)
{
Logger.Write(LogMsgSeverity.Error, ex);
throw;
}
return table;
}
private static string GetWorksheet(OleDbConnection connection, string sheetName)
{
string validSheetName = string.Empty;
using (DataTable tables = connection.GetSchema("Tables"))
{
DataRowCollection rows = tables.Rows;
if (rows.Count > 0)
{
foreach (DataRow row in rows)
{
if (row["Table_Name"].ToString().Contains(sheetName))
{
validSheetName = sheetName;
}
}
}
}
return validSheetName;
}
你看到这个问题了吗?我没有,我去看看。谢谢