1環境準備
安裝Visual Studio
根據.NETFrameWork版本下載相應的8a資料庫驅動
安裝驅動獲取相應dll檔案
2在VS中新建C#控制臺專案,在右側專案名上右鍵添加參考通過瀏覽獲取的dll檔案
3下面的樣例代碼使用連接字串通過 GBaseConnection 類創建連接物件、打開連接、關閉連接。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GBase.Data; //添加GBase相關參考
using GBase.Data.GBaseClient; //添加GBase相關參考
namespace UsingAdoNet
{
class Program
{
static void Main(string[] args)
{
GBaseConnection _Conn = new GBaseConnection();
//設定連接引數,注意IP、用戶名和密碼及資料庫需要跟自己服務器一致
_Conn.ConnectionString = "server=192.168.5.5;user id=gbase;password=gbasegbase;database=test;port=5258;pooling=false";
try
{
//獲取連接
_Conn.Open();
Console.WriteLine("連接成功");
}
catch (GBaseException ex)
{
//輸出相關例外資訊
Console.WriteLine(ex.ToString());
}
finally
{
if (_Conn != null) _Conn.Close();
//關閉連接
Console.WriteLine("關閉成功");
Console.ReadLine();
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/279471.html
標籤:C#
