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

Posted 横刀立马 醉卧山岗

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
    }
}
}

  结果如下:

技术分享

 

 

其中 

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连接数据库并使用的主要内容,如果未能解决你的问题,请参考以下文章

CUBRID学习笔记 16 元数据支持

CUBRID学习笔记 9 创建示例数据库

CUBRID学习笔记 15 Lobs类型数据

CUBRID学习笔记 11 数据类型之日期

CUBRID学习笔记 14 删除主键错误

CUBRID学习笔记 12防火墙设置 linux