简体   繁体   English

Microsoft Jet数据库引擎找不到对象

[英]The Microsoft Jet database engine could not find the object

I'm trying to upload an Excel file to a SQL database and was working fine on my computer, but once I uploaded to the server it's giving me this error: 我正在尝试将Excel文件上传到SQL数据库,并且在我的计算机上工作正常,但是一旦我将其上传到服务器,就会出现此错误:

Exception Details: System.Data.OleDb.OleDbException: The Microsoft Jet database engine could not find the object 'C:\\Windows\\SysWOW64\\inetsrv\\Book1.xls'. 异常详细信息:System.Data.OleDb.OleDbException:Microsoft Jet数据库引擎找不到对象'C:\\ Windows \\ SysWOW64 \\ inetsrv \\ Book1.xls'。 Make sure the object exists and that you spell its name and the path name correctly. 确保对象存在,并且正确拼写了它的名称和路径名。

Source Error: 源错误:

An unhandled exception was generated during the execution of the current web request. 当前Web请求的执行期间生成了未处理的异常。 Information regarding the origin and location of the exception can be identified using the exception stack trace below. 可以使用下面的异常堆栈跟踪来标识有关异常的来源和位置的信息。

Here is my code: 这是我的代码:

  protected void Button1_Click(object sender, EventArgs e) { string excelConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HRD=YES;IMEX=1'", FileUpload1.PostedFile.FileName); using (OleDbConnection connection = new OleDbConnection(excelConnectionString)) { OleDbCommand command = new OleDbCommand(("Select * FROM [Sheet1$]"), connection); connection.Open(); using (DbDataReader dr = command.ExecuteReader()) { using (SqlBulkCopy bulkCopy = new SqlBulkCopy("Data Source=WSCJTCSQ1;Initial Catalog=TestDB;Persist Security Info=True;User ID=test;Password=test")) { bulkCopy.DestinationTableName = "CoaTest"; bulkCopy.ColumnMappings.Add("First Name", "fName"); bulkCopy.ColumnMappings.Add("Last Name", "lName"); bulkCopy.ColumnMappings.Add("Agency", "agency"); bulkCopy.WriteToServer(dr); } } } Label1.ForeColor = System.Drawing.Color.Red; Label1.Text = "Successfully Uploaded The New Roster"; } 
string file = string.Format("{0}\\{1}", Request.PhysicalApplicationPath,
Guid.NewGuid().ToString().Replace("-",string.Empty));

FileUpload1.SaveAs(file)

Now in your import code 现在在您的导入代码中

string excelConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source={0};Extended Properties='Excel 8.0;HRD=YES;IMEX=1'", file);

You need to save the file on the server before you connect to it, something like: 连接文件之前,需要先将文件保存在服务器上,例如:

string sServerFilespec = ("C:\\ServerFolder\\" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName));
FileUpload1.PostedFile.FileName.SaveAs(sServerFilespec);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft Jet数据库引擎找不到对象“ ...” - The Microsoft Jet database engine could not find the object '…' Microsoft Jet数据库引擎找不到对象 - The Microsoft Jet database engine could not find the object Microsoft Jet数据库引擎找不到对象“ Sheet1 $ _” - The Microsoft Jet database engine could not find the object 'Sheet1$_' Microsoft jet 数据库引擎在读取 dbf 文件时找不到对象 - The Microsoft jet database engine could not find object while reading dbf file GetColumnName()LinqToExcel for csv文件抛出错误Microsoft Jet数据库引擎找不到对象'Sheet1 $ .txt' - GetColumnName() LinqToExcel for csv file throw error The Microsoft Jet database engine could not find the object 'Sheet1$.txt' Microsoft Jet数据库引擎找不到输入表或查询 - The Microsoft Jet database engine cannot find the input table or query Microsoft Access 数据库引擎找不到对象“Sheet1$” - The Microsoft Access database engine could not find the object 'Sheet1$ 尝试查询Excel文件时出现问题…“ Microsoft Office Access数据库引擎找不到对象'Sheet1 $'。” - Issue attempting to query an Excel file… “The Microsoft Office Access database engine could not find the object 'Sheet1$'..” Microsoft Office Access数据库引擎找不到对象“ PPR_Status_Detailed” - The Microsoft Office Access database engine could not find the object 'PPR_Status_Detailed' 使用Microsoft Jet引擎读取XLS文件 - Reading an XLS file with the Microsoft Jet Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM