外部表不是C#中的预期格式-部署后

时间:2019-01-28 11:26:33

标签: c# excel c#-4.0 oledbconnection oledbcommand

当我尝试使用C#读取excel工作表(.xlsx)时,它可以工作,但这只能是调试模式,即当我尝试从Visual Studio调试模式运行时,我正在获取工作表,并且我剃了数据库。

Then I have deployed IIS server 6.1 and I tried into client system I'm getting 
an error like 


External table is not in the expected format.
Description: An unhandled exception occurred during the execution of the 
current web request. Please review the stack trace for more information 
about the error and where it originated in the code. 

Exception Details: System.Data.OleDb.OleDbException: External table is not 
in the expected format.

Source Error: 
  Line 339:            {
  Line 340:
  Line 341:                oledbConn.Open();

我的问题

Why it's not working after deployment? 
I have tried the client and server machine(which I hosted) both I'm getting the same error

我的代码:

var connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=Yes;\"";

oledbConn.Open();
OleDbConnection oledbConn = new OleDbConnection(connString);

using (OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Project Structure with DG No$]", oledbConn ))
{
    OleDbDataAdapter oleda = new OleDbDataAdapter();
    oleda.SelectCommand = cmd;
    DataSet ds = new DataSet();
    oleda.Fill(ds);
    dt = ds.Tables[0];
}

谢谢!

0 个答案:

没有答案