【发布时间】:2023-03-05 08:27:02
【问题描述】:
我有一个使用 .NET Remoting 的客户端服务器应用程序。
我的应用程序 DBQuery 的服务器部分有一个帮助程序类。
DBQuery 持有 DatabaseConnection 和 SQLCommand 对象 Commander 并执行传递给它的查询。
每次执行查询时,都会验证 Commander 是否有打开的连接。
(如有必要,它会重新创建指挥官。)
考虑到它只连接到一个数据库,我应该将我的 DBConnection 设为静态吗?
(DBConnection 创建指挥官,DBConnection.CreateCommand())
当前属性定义如下:
/// <summary> connection used for querying with </summary>
public DBConn DBConnection
{ get { return _conn ?? (_conn = new DBConn()); } }
/// <summary> Command object for processing the queries </summary>
private SqlCommand Commander
{
get
{
return _commander ??
(_commander = DBConnection.Connection.CreateCommand());
}
}
DBConn - 包装 SqlConnection 并从 app.config 提供适当的连接信息
【问题讨论】:
标签: .net database remoting .net-remoting