2012-04-17 31 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文件的路徑是正確的

相關問題