CSFramework.DB多数据底层类库测试程序(测试报告-2021)
CSFramework.DB多数据底层类库测试程序(测试报告-2021)CSFramework.DB简介
我们在开发软件过程中,特别是基于数据管理应用相关的系统,一般采用一种数据库,如Microsoft SQL Server,超大型系统有的使用Oracle,部分Web系统采用开源的MySQL等,由于各种业务场景以及用户需求,促使我们的数据库系统部署在不同类型的数据库服务器上。若开发的系统能支持多种数据库的快速切换,可以为我们减少很多烦恼,同时提高系统的适应性、兼容性以及可扩展性。
CSFramework.DB数据库底层应用框架
CSFramework.DB测试程序主界面:
创建CSFramework.DB库的IDatabase实例:
C# Code:
C# 全选
private IDatabase _DB
{
get
{
return DatabaseFactory.CreateMDB(DatabaseType.SqlServer, txtConn.Text);
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
测试IDatabase实例的一些方法:
C# Code:
C# 全选
private void button1_Click(object sender, EventArgs e)
{
string s = _DB.ConnectionString;
ShowResult(s);
DbCommand o2 = _DB.CreateCommand("SELECT GETDATE()", System.Data.CommandType.Text);
object o9 = _DB.ExecuteCommand(o2);
ShowResult(o9);
DbCommand c1 = _DB.CreateCommand("SELECT * FROM sys_Log", System.Data.CommandType.Text);
object o20 = _DB.GetDataSet(c1);
ShowResult(o20);
object o3 = _DB.CreateCommandBuilder();
ShowResult(o3);
object o4 = _DB.CreateConnection(txtConn.Text);
ShowResult(o4);
object o5 = _DB.CreateDataAdapter();
ShowResult(o5);
object o6 = _DB.CreateParameter("@asd", "asdf");
ShowResult(o6);
object o8 = _DB.DateTimeType;
ShowResult(o8);
object o10 = _DB.ExecuteReader("SELECT * FROM sys_Log");
ShowResult(o10);
object o11 = _DB.ExecuteScalar("SELECT * FROM sys_Log");
ShowResult(o11);
object o12 = _DB.ExecuteSQL("SELECT * FROM sys_Log");
ShowResult(o12);
DbTransaction tran = _DB.TransBegin();
object o13 = _DB.ExecuteTrans(tran, "SELECT * FROM sys_Log");
ShowResult(o13);
_DB.TransRollback(tran);
object o14 = _DB.GetDataRow("SELECT TOP 1 * FROM sys_Log");
ShowResult(o14);
object o15 = _DB.GetDataSet("SELECT TOP 1 * FROM sys_Log");
ShowResult(o15);
object o16 = _DB.GetTable("SELECT TOP 1 * FROM sys_Log");
ShowResult(o16);
object o17 = _DB.ParamSymboName;
ShowResult(o17);
object o18 = _DB.GetServerTime();
ShowResult(o18);
DbParameter p = _DB.CreateParameter("@TableName", "sys_Log");
object o19 = _DB.GetDataSet("sp_sys_GetTableFieldDef", System.Data.CommandType.StoredProcedure, new System.Data.IDataParameter[] { p });
ShowResult(o19);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
IDatabase.GetTable方法:
C# Code:
C# 全选
IDatabase db = DatabaseFactory.CreateDatabase(DatabaseType.SqlServer, txtConn.Text);
DataTable dt = db.GetTable("SELECT TOP 10 * FROM dbo.sys_Log", "sys_Log");
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = dt;
//来源:C/S框架网 | www.csframework.com | QQ:23404761
设置CommandTimeOut命令超时, ConnectionTimeOut连接超时:
C# Code:
C# 全选
DatabaseFactory.CommandTimeOut = 60 * 5; //设置DbCommand命令超时:5分钟
DatabaseFactory.ConnectionTimeOut = 35;//设置数据库连接超时:35秒钟
//连接字符串指定连接超时,25秒
string connectionString = "Server=.;Database=CSFramework_WebAPI;User ID=sa;Password=test;Connection Timeout=25;";
IDatabase db = DatabaseFactory.CreateDatabase(DatabaseType.SqlServer, connectionString);
DbConnection conn = db.CreateConnection();//35s
int a = conn.ConnectionTimeout;
ShowResult(a);
//连接字符串没有指定连接超时,自动添加Connection Timeout属性
string connectionString1 = "Server=.;Database=CSFramework_WebAPI;User ID=sa;Password=test;";
IDatabase db1 = DatabaseFactory.CreateDatabase(DatabaseType.SqlServer, connectionString1);
DbConnection conn1 = db1.CreateConnection();
int a1 = conn1.ConnectionTimeout;//35s
ShowResult(a1);
//来源:C/S框架网 | www.csframework.com | QQ:23404761
创建 DbProviderFactory 数据库工厂:
C# Code:
C# 全选
DbProviderFactory factory1 = DataProviderFactory.GetFactory(DatabaseType.SqlServer);
ShowResult(factory1);
DbProviderFactory factory2 = DataProviderFactory.GetFactory(DatabaseType.MySQL);
ShowResult(factory2);
DbProviderFactory factory3 = DataProviderFactory.GetFactory(DatabaseType.Oracle);
ShowResult(factory3);
//来源:C/S框架网 | www.csframework.com | QQ:23404761
扫一扫加微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网