C#鏈接Informix數據庫

最近在工做中遇到了須要鏈接Informix數據庫的問題,在經過研究後發現了能夠經過多種方式實現,我選擇的是經過IBM Informix .NET Provider。該方式須要引用IBM.Data.Informix.dll。數據庫

 1 using IBM.Data.Informix;
 3 using System; 7 
 8 namespace InformixLinkTest
 9 {
10     class Program
11     {
12         static void Main(string[] args)
13         {
14             try
15             {
16                 // Open a connection
17                 IfxConnection conn = new IfxConnection(
18                 "Host=127.0.0.1;Service=9098;"
19                 + "Server=informixserver;Database=MyDatabase;"
20                 + "User ID=informix;password=MyPassword;db_locale=en_us.819"
21                 );
22                 conn.Open();
23                 IfxDataReader rd;
24                 using (IfxCommand cmd = conn.CreateCommand())
25                 {
26                     cmd.CommandText = "select * from simpletable";
27                     rd = cmd.ExecuteReader();
28                     rd.Read();
29                     do
30                     {
31                         if (rd.HasRows)
32                         {
33                             ///Assuming the table has two columns
34                             Console.WriteLine("{0}", rd[0]);
35                         }
36 
37                     } while (rd.Read());
38                 }
39                 conn.Close();
40             }
41             catch (IfxException e)
42             {
43                 Console.WriteLine(e.ToString());
44                 Console.ReadLine();
45             }
46     }
47 }

在調試過程當中會發現出現異常(System.DllNotFoundException:「沒法加載 DLL「IfxDotNetIntrinsicModule.dll」: 找不到指定的模塊。 (異常來自 HRESULT:0x8007007E)。」),具體如圖:,經過提示能夠看到找不到IfxDotNetIntrinsicModule.dll,我經過在安裝Informix數據庫的路徑中找到了這個包放到了bin文件夾下後ide

 

 

,就能正常運行了。spa

另外一個問題就是在鏈接串中最開始db_locale的值我是給的utf8,按照這個也會出現異常狀況,異常代碼爲(ERROR [HY000] [Informix .NET provider][Informix]Database locale information mismatch. ),截圖以下:,最後將其設置爲db_locale=en_us.819後就可正常鏈接到informix數據庫。調試

相關文章
相關標籤/搜索