CSFramework.DB关于设置全局变量CommandTimeOut/ConnectionTimeOut的测试案例
CSFramework.DB关于设置全局变量CommandTimeOut/ConnectionTimeOut的测试案例
测试DbConnection组件的ConnectionTimeout属性。
测试DbConnection组件的ConnectionTimeout属性。
测试DbCommand组件的CommandTimeout属性。
本实例源码来自CSFramework.DB的frmTestDB.cs。
客户应用系统中设置全局变量CommandTimeOut/ConnectionTimeOut的属性值。
C# Code:
DatabaseFactory.CommandTimeOut = 60 * 5; //设置DbCommand命令超时:5分钟
DatabaseFactory.ConnectionTimeOut = 35;//设置数据库连接超时:35秒钟
DatabaseFactory.CommandTimeOut = 60 * 5; //设置DbCommand命令超时:5分钟
DatabaseFactory.ConnectionTimeOut = 35;//设置数据库连接超时:35秒钟
测试DbConnection组件的ConnectionTimeout属性。
C# Code:
//连接字符串指定连接超时,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;
Console.Write(a);
//来源:C/S框架网(www.csframework.com) QQ:23404761
//连接字符串指定连接超时,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;
Console.Write(a);
//来源:C/S框架网(www.csframework.com) QQ:23404761
C# Code:
//连接字符串没有指定连接超时,自动添加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
Console.Write(a1);
Console.Write(conn1.ConnectionString);
//来源:C/S框架网(www.csframework.com) QQ:23404761
//连接字符串没有指定连接超时,自动添加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
Console.Write(a1);
Console.Write(conn1.ConnectionString);
//来源:C/S框架网(www.csframework.com) QQ:23404761
C# Code:
//测试命令超时
DbCommand cmd = db.CreateCommand("SELECT COUNT(*) FROM Api_User", CommandType.Text);
cmd.Connection = conn;
int i = cmd.CommandTimeout;
object o = cmd.ExecuteScalar();
Console.Write(a);//300s
//来源:C/S框架网(www.csframework.com) QQ:23404761
//测试命令超时
DbCommand cmd = db.CreateCommand("SELECT COUNT(*) FROM Api_User", CommandType.Text);
cmd.Connection = conn;
int i = cmd.CommandTimeout;
object o = cmd.ExecuteScalar();
Console.Write(a);//300s
//来源:C/S框架网(www.csframework.com) QQ:23404761
本实例源码来自CSFramework.DB的frmTestDB.cs。
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网