Home > Net >  GBase ADO.NET to create a database connection
GBase ADO.NET to create a database connection

Time:04-24

Environment to prepare 1
Install Visual Studio
According to. NETFrameWork version download corresponding 8 a database driven
Install the driver for the corresponding DLL file
2 in VS new c # console project, right-click on the project name on the right side add references by browsing for the DLL file
3 this sample code USES the connection string by GBaseConnection class to create a connection object, to open the connection, close the connection,

using System;
using System.Collections.Generic;
Using System. Linq;
using System.Text;
Using GBase. Data;//add GBase related reference
Using GBase. Data. GBaseClient;//add GBase related reference

The namespace UsingAdoNet
{
Class Program
{
The static void Main (string [] args)
{
GBaseConnection _Conn=new GBaseConnection ();
//set the connection parameters, pay attention to the IP, user name and password, and database needs to be consistent with their own server
_Conn. The ConnectionString="server=192.168.5.5; User id=gbase; Password=gbasegbase; The database=test; Port=5258; Pooling=false ";
Try
{
//get connection
_Conn. The Open ();
Console. WriteLine (" connection success ");
}
The catch (GBaseException ex)
{
//output related exceptions information
Console. WriteLine (ex. ToString ());
}
The finally
{
If (_Conn!=null) _Conn. Close ();
//close the connection
Console. WriteLine (" closed success ");
Console.ReadLine();
}

}
}
}
  •  Tags:  
  • C#
  • Related