2013-03-20 78 views
7

我對Access數據庫使用OleDbConnection,OldDbCommand和OleDbReader。是什麼導致我的OLEDbException,IErrorInfo.GetDescription失敗,E_FAIL(0x80004005)

我在數據庫中有一個命名的查詢,我從代碼調用。

查詢從訪問運行時正常工作。

幾個資源表明錯誤可能是由於在查詢中使用保留字並使用括號來包裝它們造成的。我沒有使用任何保留字,並將括號中的所有列名稱都排除在外。

試圖確定問題出在哪裏,我簡化了查詢,以一個簡單的

SELECT id FROM table1 WHERE id = 5 

其中奧萊連接不拋出異常。

當我介紹了查詢的下一部分:

SELECT table1.id FROM table1 INNER JOIN storedQuery ON table1.id = storedQuery.id WHERE table1.id = 5" 

然後我得到的異常。

異常的詳細信息如下:

  • Message: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
  • ErrorCode: -2147467259
  • NativeError: -533136361
  • SQLState: 3000

回答

9

我顯然是錯誤的,當我說查詢沒有包含任何保留字。

我正在使用的查詢是從Access數據庫中的另一個查詢中進行選擇。該另一個查詢具有導致該問題的保留關鍵字。

BTW:

The Access database engine runs in different modes, depending on whether it is called from Access, data access objects, the Microsoft OLE Provider for the Access database engine, or the Microsoft Access ODBC driver. It can be run in either ANSI mode or non-ANSI (traditional) mode.

Because using these two modes results in two slightly different sets of reserved words, a query that uses a reserved word might work in one mode and fail in another mode

Access 2007 reserved words and symbols

基思

+0

缺貨好奇心,查詢中保留關鍵字失敗的原因是什麼? – DaveInCaz 2017-10-17 11:56:06

+1

太多年前要記住..對我來說重要的一部分是發現有不同的保留字取決於你調用存儲的查詢的方式 – 2017-10-19 14:27:04

2

此異常的另一個可能的原因是,如果你的文件試圖加載/讀取不存在。

我發現在試圖打開文件之前執行「File.Exists」,只是爲了確保我的代碼正確檢測到「IErrorInfo.GetDescription failed with E_FAIL」異常的特定原因。

4

..and have wrapped all column names in brackets anyway to rule it out.

不僅列名應該由方括號包圍 表名應該以及 例如,代替下面線

SELECT id FROM table1 WHERE id = 5 

隨着下面線

SELECT [id] FROM [table1] WHERE [id] = 5 
相關問題