2012-04-17 29 views
0

我有一个非常简单的ASP.net 4.0应用程序,它允许用户从常见的Excel文件中读取数据。 Excel文件位于应用程序本身内,即它驻留在服务器端的根目录下的文件夹中。尝试读取Excel文件时发生COM互操作异常ASP.net

我填充使用此代码Excel数据一个数据集:

public DataTable GetExcelData(string ExcelFilePath) 
    { 
     DataTable dt = new DataTable(); 
     string OledbConnectionString = string.Empty; 
     OleDbConnection objConn = null; 
     OledbConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ExcelFilePath + ";Extended Properties=Excel 8.0;"; 
     objConn = new OleDbConnection(OledbConnectionString); 

     if (objConn.State == ConnectionState.Closed) 
     { 
      objConn.Open(); 
     } 

     string resName = "'"; 
     string depName = department; 
     resName += userLastName + ", " + userFirstName + "'"; 
     OleDbCommand objCmdSelect = new OleDbCommand("Select * from [" + depName + "$A3:Q10000] where Resource=" + resName, objConn); 
     OleDbDataAdapter objAdapter = new OleDbDataAdapter(); 
     objAdapter.SelectCommand = objCmdSelect; 
     DataSet objDataset = new DataSet(); 
     objAdapter.Fill(objDataset, "ExcelDataTable"); 
     dt = objDataset.Tables[0]; 
     addSumRow(dt); 
     objConn.Close(); 
     return objDataset.Tables[0]; 
    } 

并在此之后我武官数据集到GridView,这就是它。

现在,当我在我的本地主机上运行的应用程序有显示Excel数据没有问题,但是,应用程序失败,此错误部署到Web服务器后:

The specified domain either does not exist or could not be contacted.

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.Runtime.InteropServices.COMException: The specified domain >either does not exist or could not be contacted.

Source Error:

An unhandled exception was generated during the execution of the current web request. >Information regarding the origin and location of the exception can be identified using >the exception stack trace below.

任何帮助是非常赞赏! 谢谢!

+0

好像误差不化的Excel文件。如果你看附加的代码,错误是从Default.aspx.cs:239(SearchResult userInfo = search.FindOne())在我正在做一个AD查找获取用户名等位置生成的 – peer754 2012-04-17 08:59:19

回答

0

几件事你可以尝试

1>禁用匿名访问并启用身份模拟 2>确保Excel文件的路径是正确的

相关问题