我正在尝试在我的 asp.net 网站上阅读 Excel 表。文件由用户上传,然后我阅读它并在网格视图中显示结果。当我在 Visual Studio 环境中运行它时,一切正常。但是当我在 IIS 上尝试相同的代码时,它给出了 Exception Unspecified Error
。我正在使用以下代码:
string excelConnection = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+Server.MapPath("~/doc/")+ filepath+";Extended Properties="+ "\"" + "Excel 12.0;HDR=YES;" + "\"";
string query = "select * from [Sheet1$]";
OleDbConnection con = new OleDbConnection(connection);
con.Open(); // Exceptionoccurs here
OleDbCommand cmd = new OleDbCommand(query, con);
cmd.CommandType = CommandType.Text;
OleDbDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
testGrid.DataSource = dt;
testGrid.DataBind();
异常堆栈跟踪:
[OleDbException (0x80004005): Unspecified error]
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +351
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +86
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +31
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +76
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
System.Data.OleDb.OleDbConnection.Open() +43
DataBaseSolution.DbSolution.select(String connection, String providername, String query) in F:\vs backup\DataBaseSolution\DataBaseSolution\DbSolution.cs:63
_Default.insertDb(String filepath) in c:\inetpub\wwwroot\test\Default.aspx.cs:82
_Default.checkButton_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\test\Default.aspx.cs:39
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
请向我建议任何代码更新或任何其他我可以完成此任务的方法。
已编辑:提供堆栈跟踪并用注释标记行,其中出现异常