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