1. 程式人生 > 程式設計 >C#連線Informix資料庫的問題

C#連線Informix資料庫的問題

引言

Informix 11 與之前版本的 Informix 相比,新增了很多特性,如 SQL 語句跟蹤、非阻斷的檢查點、SDS 輔節點、星型連線、自動儲存擴充套件、圖形介面的管理工具 OAT 等,並且在效能上有了很大的提升。另外,由於 Informix 版本 7、9、10 已進入 EOS (End Of Support) 狀態,所以很多 Informix 使用者紛紛選擇將 Informix 升級到版本 11。

Informix 資料庫升級簡介

Informix 資料庫升級是指把使用的 Informix 資料庫從低版本轉化為高版本。對 Informix 資料庫進行升級是一項系統工程,包括升級前的測試、升級前的檢查、升級操作過程、升級後的測試、升級後的調優等。

Informix 資料庫升級有兩種型別:in-place 和 non-in-place。In-place 升級中,新版本的 Informix 使用的資料檔案與舊版本的 Informix 相同,資料庫管理員無需匯出匯入資料。Non-in-place 升級中,新版本的 Informix 使用的資料檔案與舊版本的 Informix 不同,資料庫管理員需要匯出匯入資料。

In-place 升級比較簡單,升級操作時間短。non-in-place 升級比較複雜,升級操作時間長,所需的硬體資源多,風險較小。在一些情況下我們只能使用 non-in-place 升級,例如改變了硬體或作業系統。

兩種型別的 Informix 資料庫升級的示意圖如圖 1 所示。

圖 1. 兩種型別的 Informix 資料庫升級的示意圖

C#連線Informix資料庫的問題

兩種型別的 Informix 資料庫升級的示意圖

正文

最近在工作中遇到了需要連線Informix資料庫的問題,在通過研究後發現了可以通過多種方式實現,我選擇的是通過IBM Informix .NET Provider。該方式需要引用IBM.Data.Informix.dll。

using IBM.Data.Informix;
using System; 7 
namespace InformixLinkTest
{
 class Program
 {
  static void Main(string[] args)
  {
   try
   {
    // Open a connection
    IfxConnection conn = new IfxConnection(
    "Host=127.0.0.1;Service=9098;"
    + "Server=informixserver;Database=MyDatabase;"
    + "User ID=informix;password=MyPassword;db_locale=en_us.819"
    );
    conn.Open();
    IfxDataReader rd;
    using (IfxCommand cmd = conn.CreateCommand())
    {
     cmd.CommandText = "select * from simpletable";
     rd = cmd.ExecuteReader();
     rd.Read();
     do
     {
      if (rd.HasRows)
      {
       ///Assuming the table has two columns
       Console.WriteLine("{0}",rd[0]);
      }

     } while (rd.Read());
    }
    conn.Close();
   }
   catch (IfxException e)
   {
    Console.WriteLine(e.ToString());
    Console.ReadLine();
   }
 }
}

在除錯過程中會發現出現異常(System.DllNotFoundException:“無法載入 DLL“IfxDotNetIntrinsicModule.dll”: 找不到指定的模組。 (異常來自 HRESULT:0x8007007E)。”),具體如圖:

C#連線Informix資料庫的問題

通過提示可以看到找不到IfxDotNetIntrinsicModule.dll,我通過在安裝Informix資料庫的路徑中找到了這個包放到了bin資料夾下後

C#連線Informix資料庫的問題

就能正常運行了。

另一個問題就是在連線串中最開始db_locale的值我是給的utf8,按照這個也會出現異常情況,異常程式碼為(ERROR [HY000] [Informix .NET provider][Informix]Database locale information mismatch. ),截圖如下:

C#連線Informix資料庫的問題

最後將其設定為db_locale=en_us.819後就可正常連線到informix資料庫。

總結

到此這篇關於C#連線Informix資料庫的問題的文章就介紹到這了,更多相關C#連線Informix資料庫內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!