zoukankan      html  css  js  c++  java
  • CUBRID学习笔记 3 net连接数据库并使用cubrid教程示例

    接上文

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

    下面我们用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();
        }
    }
    }

      结果如下:

    其中 

    AutoCommit  是否自动提交事务
    我简单的理解 :如果不手动用事务的话 ,可以开启.如果手动控制事务的话 ,关闭它  .  然后 手动提交 COMMIT WORK;
    SetAutoCommit的说明如下 :


    sql语句中: AUTOCOMMIT IS OFF
    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.

    c#,net,cubrid,教程,学习,笔记欢迎转载 ,转载时请保留作者信息。本文版权归本人所有,如有任何问题,请与我联系wang2650@sohu.com 。 过错

    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的.

    如果感兴趣可以看源码吧

  • 相关阅读:
    8.Nginx常用基础模块
    7.Web基础之Nginx
    6.Web基础之http协议
    5.SSH远程服务
    4.Sersync实时同步
    3.NFS 共享存储
    前端-CSS
    前端-HTTP
    MySQL-其他知识点
    MySQL-pymysql模块
  • 原文地址:https://www.cnblogs.com/wang2650/p/5282848.html
Copyright © 2011-2022 走看看