C#操作Informix数据库
来源:互联网 发布:c语言进程的创建 编辑:程序博客网 时间:2024/05/01 07:53
在做开发的过程中,有时会向数据库中插入大批量数据,比如几十万条记录。由于这次使用的是Informix,这个数据库的客户端都不怎么好用,导入数据总是出问题,于是干脆自己写个程序,把记录从文件中读出来,插入到数据库中。本来想写个C++程序,发现ifstream读了几万条记录就不行了,ifstream.good()就通不过。还是写个c#的吧。
c#连接数据库,需要引入IBM.Data.Informix.dll。这个动态链接库是安装Informix时在安装目录可以找到的。
下面是例子程序:
using System;using System.Collections.Generic;using System.Text;using IBM.Data.Informix;using IBM.Data.Utilities;using System.IO;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { try { // Open a connection IfxConnection conn = new IfxConnection( "Host=192.168.221.140;Service=9091;" + "Server=test_server;Database=NX_Localization;" + "User ID=informix;password=jim480;db_locale=en_us.utf8" ); conn.Open(); FileStream ifs = new FileStream("pybknm.sql", FileMode.Open); StreamReader sr = new StreamReader(ifs, System.Text.Encoding.Default); String strLine; int cnt = 0; while ((strLine = sr.ReadLine()) != null) { cnt++; IfxCommand cmd = new IfxCommand(strLine, conn); cmd.CommandTimeout = 200; int row = 0; try { row = cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("cnt=" + cnt); if(row!=1) break; } Console.WriteLine("cnt=" + cnt); Console.ReadLine(); conn.Close(); } catch (IfxException e) { Console.WriteLine(e.ToString()); Console.ReadLine(); } } }}
- C#操作Informix数据库
- informix数据库常用操作
- informix数据库操作
- Informix操作
- informix数据库
- Informix数据库配置
- informix数据库基础
- .net连接Informix数据库
- jsp连接informix数据库
- informix数据库中锁表处理
- 连接informix数据库字符串
- INFORMIX数据库隔离级别
- Informix 数据库的数据类型
- 修改informix数据库主键
- JDBC连接INFORMIX数据库
- Informix数据库系统表
- Informix数据库调优
- Informix数据库安装配置
- 【C++】fwrite与fread
- hrust OJ 1316 移动II
- 黑马程序员----【javaSE基础】IO--字节流
- hdu 4619(sap解二分匹配)
- hdu4300
- C#操作Informix数据库
- 又议android中的manifest清单文件
- 黑马程序员----【javaSE基础】IO--字符流
- UVA 350 Pseudo-Random Numbers
- C++虚函数与虚函数表(编译器查看)
- 黑马程序员—SQL系列 (一)
- 如何添加账户到sudoers
- STL中的set容器的一点总结
- UVA 10392 Factoring Large Numbers