星空网 > 软件开发 > 数据库

CUBRID学习笔记 3 net连接数据库并使用

接上文

数据库安装好后,也可以测试语句了.

下面我们用c#写一个控制台程序,连接数据库,并读取数据.

一 下载驱动  net版的下 CUBRID ADO.NET Data Provider 9.3.0.0001.zip 这个就可以.解压后里面有一个CUBRID.Data.dll

二 创建控制台,添加对CUBRID.Data.dll的引用

三 写代码

如下

using System;using System.Collections.Generic;using System.Linq;using System.Text;using CUBRID.Data.CUBRIDClient;namespace cubridtest {class Program {  static void Main(string[] args)  {    CUBRID.Data.CUBRIDClient.CUBRIDConnectionStringBuilder sb = new CUBRIDConnectionStringBuilder();    sb.User = "public";    sb.Database = "demodb";    sb.Port = "33000";    sb.Server = "192.168.2.156";    sb.Password = "";    using (CUBRIDConnection conn = new CUBRIDConnection(sb.GetConnectionString()))    {      conn.Open();      conn.SetAutoCommit(false);      using (CUBRIDCommand cmd = new CUBRIDCommand("select * from athlete limit 1,10", conn))      {        using (System.Data.Common.DbDataReader reader = cmd.ExecuteReader())        {          while (reader.Read())          {            Console.WriteLine( reader[0].ToString()+";");          }        }      }    }    Console.ReadKey();  }}}

  结果如下:

CUBRID学习笔记 3   net连接数据库并使用

 

 

其中 

SetAutoCommit的说明如下
CCI_DEFAULT_AUTOCOMMIT

CCI_DEFAULT_AUTOCOMMIT is a parameter used to configure whether to make application implemented in CCI interface or CCI-based interface such as PHP, ODBC, OLE DB, Perl, Python, and Ruby commit automatically. The default value is ON. This parameter does not affect applications implemented in JDBC. In case of using ODBC, malfunction can occur if this parameter is ON; you must set it to OFF, in this case.

If the CCI_DEFAULT_AUTOCOMMIT parameter value is OFF, the broker application server (CAS) process is occupied until the transaction is terminated. Therefore, it is recommended to execute commit after completing fetch when executing the SELECTstatement.

 

Note The CCI_DEFAULT_AUTOCOMMIT parameter has been supported from 2008 R4.0, and the default value is OFF for the version. Therefore, if you use CUBRID 2008 R4.1 or later versions and want to keep the configuration OFF, you should manually change it to OFF to avoid auto-commit of unexpected transaction.

更详细的文档 http://www.cubrid.org/wiki_apis/entry/ado-net-driver-development-notes  最新版是9.3了,这个文章是8的.

如果感兴趣可以看源码吧

 




原标题:CUBRID学习笔记 3 net连接数据库并使用

关键词:数据库

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

孟加拉国孟历新年:https://www.goluckyvip.com/tag/38649.html
新兴市场:https://www.goluckyvip.com/tag/3865.html
孟加拉海运费用:https://www.goluckyvip.com/tag/38650.html
孟加拉海运专线:https://www.goluckyvip.com/tag/38651.html
孟想研究院:https://www.goluckyvip.com/tag/38652.html
梦龙的笔记:https://www.goluckyvip.com/tag/38653.html
丽人丽妆2023年扭亏为盈 玉容初、美壹堂等自有品牌增速超40% :https://www.kjdsnews.com/a/1836576.html
一天拿下10万美金预售!深圳大卖出海第一年成为亚马逊供应商:https://www.kjdsnews.com/a/1836577.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流