我最近将我的SQL连接字符串更新为Microsoft.ACE.OLEDB.12.0
,现在就是:
using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data.Common;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Media;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
// connection for header file
protected OleDbCommand headExcelConnection()
{
// Connect to the Excel Spreadsheet
string headConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Server.MapPath("~/imports/headerorder.xls") + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection headXConn = new OleDbConnection(headConnStr);
headXConn.Open();
OleDbCommand headCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", headXConn);
return headCommand;
headXConn.Close();
}
我在第headXConn.Open()
行发现了以下错误;
异常详细信息:System.Runtime.InteropServices.SEHException: 外部组件抛出异常。
SEHException(0x80004005):外部组件抛出了一个 例外]
System.Data.Common.IDBInitializeInitialize.Invoke(IntPtr pThis)+0
System.Data.OleDb.DataSourceWrapper.InitializeAndCreateSession(OleDbConnectionString constr,SessionWrapper& sessionWrapper)+304
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr,OleDbConnection连接)+193
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options,Object poolGroupProviderInfo,DbConnectionPool池, DbConnection owningObject)+86
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(的DbConnection owningConnection,DbConnectionPoolGroup poolGroup)+29
System.Data.ProviderBase.DbConnectionFactory.GetConnection(的DbConnection 拥有连接)+4911420
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(的DbConnection outerConnection,DbConnectionFactory connectionFactory)+117
System.Data.OleDb.OleDbConnection.Open()+40
exportsEmails.aspx.cs中的importsEmails.headExcelConnection():65
importsEmails.BtnViewHeader_Click(Object sender,EventArgs e)in importsEmails.aspx.cs:89个
System.Web.UI.WebControls.Button.OnClick(EventArgs e)+111
System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串 eventArgument)+110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 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)
我做错了什么?