CUBRID学习笔记 3 net连接数据库并使用cubrid教程示例
接上文
數(shù)據(jù)庫安裝好后,也可以測(cè)試語句了.
下面我們用c#寫一個(gè)控制臺(tái)程序,連接數(shù)據(jù)庫,并讀取數(shù)據(jù).
一 下載驅(qū)動(dòng) ?net版的下?CUBRID ADO.NET Data Provider 9.3.0.0001.zip 這個(gè)就可以.解壓后里面有一個(gè)CUBRID.Data.dll
二 創(chuàng)建控制臺(tái),添加對(duì)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();} } }結(jié)果如下:
?
?
其中?
AutoCommit 是否自動(dòng)提交事務(wù) 我簡(jiǎn)單的理解 :如果不手動(dòng)用事務(wù)的話 ,可以開啟.如果手動(dòng)控制事務(wù)的話 ,關(guān)閉它 . 然后 手動(dòng)提交 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,教程,學(xué)習(xí),筆記歡迎轉(zhuǎn)載 ,轉(zhuǎn)載時(shí)請(qǐng)保留作者信息。本文版權(quán)歸本人所有,如有任何問題,請(qǐng)與我聯(lián)系wang2650@sohu.com 。 過錯(cuò)
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.
更詳細(xì)的文檔?http://www.cubrid.org/wiki_apis/entry/ado-net-driver-development-notes ?最新版是9.3了,這個(gè)文章是8的.
如果感興趣可以看源碼吧
?
轉(zhuǎn)載于:https://www.cnblogs.com/wang2650/p/5282848.html
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的CUBRID学习笔记 3 net连接数据库并使用cubrid教程示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MAVEN学习笔记-maven的获取和安
- 下一篇: ps命令用法