2014-01-13 84 views
-1

不知道我做错了什么在这里,但我不断收到对connection.Open();线以下异常:错误连接到Excel电子表格

IErrorInfo.GetDescription failed with E_FAIL(0x80004005) 

问题是我几乎是完全相同的代码在另一个批处理作业它工作正常。我们甚至从同一地点提取电子表格。有没有人看到我的连接或查询字符串有什么问题?

static void Main(string[] args) 
    { 
     string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= \\prdhilfs03\l&i-sales&mkt\WORKAREA\Agencyservices\Shared\AIC\Analysts_and_Reporting\Realignments\2014\MassUpdateTesting\ZipCodeTest.xslx;Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"; 
     string queryString = "SELECT * FROM [Query1$]"; 


     try 
     { 
      OleDbDataReader reader; 
      using (OleDbConnection connection = new OleDbConnection(connString)) 
      { 
       //Set connection objects to pull from spreadsheet 
       OleDbCommand command = new OleDbCommand(queryString, connection); 
       connection.Open(); 

良好的措施,这里的工作簿的屏幕截图,我试图连接到

enter image description here

+0

downvote是什么原因? – NealR

+0

您是否尝试过检查您是否可以访问该文件? string xlFile = @“\\ prdhilfs03 \ l&i-sales&mkt \ ...... \ ZipCodeTest.xlsx”;控制台.WriteLine(File.Exists(xlFile)?“Excel文件存在。”:“Excel文件不存在。”); – crackhaus

+0

原来我在连接字符串中有一个拼写错误,谢谢。如果你想提供这种技术作为答案,我会接受它。 (再次!) – NealR

回答

1

你尝试检查您是否可以访问该文件?

string xlFile = @"\\prdhilfs03\l&i-sales&mkt\......\ZipCodeTest.xlsx"; 
Console.WriteLine(File.Exists(xlFile) ? "Excel File exists." : "Excel File does not exist.");