人大金仓数据库管理系统KingbaseES(简称:金仓数据库或KingbaseES)是北京人大金仓信息技术股份有限公司自主研制开发的具有自主知识产权的通用关系型数据库管理系统。 金仓数据库主要面向事务处理类应用,兼顾各类数据分析类应用,可用做管理信息系统、业务及生产系统、决策支持系统、多维数据分析、全文检索、地理信息系统、图片搜索等的承载数据库。金仓数据库的最新版本为KingbaseES V8, KingbaseES V8在系统的可靠性、可用性、性能和兼容性等方面进行了重大改进,支持多种操作系统和硬件平台支持Unix、Linux和Windows等数十个操作系统产品版本;支持X86、X86_64及国产龙芯、飞腾、申威等CPU硬件体系结构。并具备与这些版本服务器和管理工具之间的无缝互操作能力。 [1] 针对不同类型的客户需求,KingbaseES V8设计并实现了企业版、标准版、专业版版等多类版本。这些版本全部构建于同一数据库引擎内。在不同平台上,这些版本完全兼容。KingbaseES V8数据库应用程序可从笔记本电脑扩展到台式机、大型数据库服务器,以至整个企业网络
人大金仓试用版下载地址:人大金仓
public class KingbaseESDbHelper
{
string hibernateConfigFile = "hibernate.cfg.xml";
DbConnection connection;
public KingbaseESDbHelper()
{
Configuration result = new Configuration();
if (hibernateConfigFile != null)
result.Configure(hibernateConfigFile);
IConnectionProvider prov = ConnectionProviderFactory.NewConnectionProvider(result.Properties);
connection = prov.GetConnection();
}
public DbCommand GetStoredProcCommond(string storedProcedure)
{
DbCommand Command = connection.CreateCommand();
Command.CommandText = storedProcedure;
Command.CommandType = CommandType.StoredProcedure;
return Command;
}
public DbCommand GetSqlStringCommond(string sqlQuery)
{
DbCommand Command = connection.CreateCommand();
Command.CommandText = sqlQuery;
Command.CommandType = CommandType.Text;
return Command;
}
#region 增加参数
public void AddParameterCollection(DbCommand cmd, DbParameterCollection dbParameterCollection)
{
foreach (DbParameter dbParameter in dbParameterCollection)
{
cmd.Parameters.Add(dbParameter);
}
}
public void AddOutParameter(DbCommand cmd, string parameterName, DbType dbType, int size)
{
DbParameter dbParameter = cmd.CreateParameter();
dbParameter.DbType = dbType;
dbParameter.ParameterName = parameterName;
dbParameter.Size = size;
dbParameter.Direction = ParameterDirection.Output;
cmd.Parameters.Add(dbParameter);
}
public void AddInParameter(DbCommand cmd, string parameterName, DbType dbType, object value)
{
DbParameter dbParameter = cmd.CreateParameter();
dbParameter.DbType = dbType;
dbParameter.ParameterName = parameterName;
dbParameter.Value = value;
dbParameter.Direction = ParameterDirection.Input;
cmd.Parameters.Add(dbParameter);
}
public void AddReturnParameter(DbCommand cmd, string parameterName, DbType dbType)
{
DbParameter dbParameter = cmd.CreateParameter();
dbParameter.DbType = dbType;
dbParameter.ParameterName = parameterName;
dbParameter.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(dbParameter);
}
public DbParameter GetParameter(DbCommand cmd, string parameterName)
{
return cmd.Parameters[parameterName];
}
#endregion 增加参数
#region 执行
public DataSet ExecuteDataSet(DbCommand cmd)
{
try
{
if (cmd.Connection.State == ConnectionState.Closed)
{
cmd.Connection.Open();
}
DataSet ds = new DataSet();
using (DbDataReader reader = cmd.ExecuteReader())
{
DataTable dataTable = new DataTable();
dataTable.Load(reader);
ds.Tables.Add(dataTable); // 如果你有多个表,就重复这个过程
dataTable.Dispose();
}
return ds;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (cmd.Connection.State == ConnectionState.Open)
{
cmd.Connection.Close();
}
}
}
public DataTable ExecuteDataTable(DbCommand cmd)
{
try
{
if (cmd.Connection.State == ConnectionState.Closed)
{
cmd.Connection.Open();
}
DataTable dataTable = new DataTable();
// 模拟使用DbDataReader填充DataTable
using (DbDataReader reader = cmd.ExecuteReader())
{
dataTable.Load(reader);
}
return dataTable;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (cmd.Connection.State == ConnectionState.Open)
{
cmd.Connection.Close();
}
}
}
public DbDataReader ExecuteReader(DbCommand cmd)
{
try
{
if (cmd.Connection.State == ConnectionState.Closed)
{
cmd.Connection.Open();
}
DbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return reader;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (cmd.Connection.State == ConnectionState.Open)
{
cmd.Connection.Close();
}
}
}
public int ExecuteNonQuery(DbCommand cmd)
{
try
{
if (cmd.Connection.State == ConnectionState.Closed)
{
cmd.Connection.Open();
}
int ret = cmd.ExecuteNonQuery();
return ret;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (cmd.Connection.State == ConnectionState.Open)
{
cmd.Connection.Close();
}
}
}
public object ExecuteScalar(DbCommand cmd)
{
try
{
if (cmd.Connection.State == ConnectionState.Closed)
{
cmd.Connection.Open();
}
object ret = cmd.ExecuteScalar();
if (cmd.Connection.State == ConnectionState.Open)
{
cmd.Connection.Close();
}
return ret;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (cmd.Connection.State == ConnectionState.Open)
{
cmd.Connection.Close();
}
}
}
#endregion 执行
}
需要导入BouncyCastle.dll、Kdbndp.dll、KdbndpDialect.dll、NHibernate.dll、System.Runtime.CompilerServices.Unsafe.dll和hibernate.cfg.xml文件
测试Demo
KingbaseESDbHelper dbHelper = new KingbaseESDbHelper();
try
{
DbCommand cmd = dbHelper.GetSqlStringCommond(@"DELETE FROM wmsdb.table_1");
cmd.CommandTimeout = 10000;
dbHelper.ExecuteNonQuery(cmd);
}
catch
{
}
try
{
DbCommand cmd = dbHelper.GetSqlStringCommond(@"INSERT INTO wmsdb.table_1(COLUMN_2)VALUES('" + DateTime.Now.ToString("yyMMddHHmmssfff") + "') ; ");
cmd.CommandTimeout = 10000;
dbHelper.ExecuteNonQuery(cmd);
}
catch
{
}
try
{
DbCommand cmd = dbHelper.GetSqlStringCommond("INSERT INTO wmsdb.table_1(COLUMN_2)VALUES(@COLUMN_2) ; ");
cmd.CommandTimeout = 10000;
dbHelper.AddInParameter(cmd, "@COLUMN_2", DbType.String, DateTime.Now.ToString("yyMMddHHmmssfff"));
dbHelper.ExecuteNonQuery(cmd);
}
catch
{
}
try
{
DbCommand cmd = dbHelper.GetSqlStringCommond(@"select * from wmsdb.table_1; ");
cmd.CommandTimeout = 10000;
DataTable data = dbHelper.ExecuteDataTable(cmd);
if (data != null)
{
}
}
catch
{
}
#region //存储过程
try
{
DbCommand cmd = dbHelper.GetStoredProcCommond(@"WMSDB.CE");
cmd.CommandTimeout = 10000;
dbHelper.AddInParameter(cmd, "@NAME", DbType.String, DateTime.Now.ToString("yyMMddHHmmssfff"));
dbHelper.AddOutParameter(cmd, "@HH", DbType.String, 1000);
dbHelper.ExecuteNonQuery(cmd);
string HH = dbHelper.GetParameter(cmd, "@HH").Value.ToString();
MessageBox.Show(HH);
}
catch
{
}
#endregion