A Database class with C # with KeepConnection switches

xiaoxiao2021-03-06  19

Using system.data; using system.data.sqlclient;

Namespace CNKK.DATA {///

/// SQL Database. /// public class database: disposablebase {private string connectionstring; private sqlconnection connection;

Protected Database (String Connectionstring) {this.connectionstring = connection;

Protected Database (SqlConnection Connection) {this.Connection = Connection;

Protected Override Void DisposeManaged () {base.disposemanaged ();

this.Connection.dispose ();

Private SqlConnection getConnection () {if (KeepConnection) {Return this.Connection;} else {returnnection;}}

Protected SqlConnection Connection {Get {Return this.Connection;}}

Private int commandtimeout = 30;

///

/// Set the time (in seconds) waiting for the command to execute. /// public static int commandtimeout {set {this.commandtimeout = value;}}

///

/// Database connection string. /// public string connectionstring {get {returnnection.connectionstring;}}

Private bool KeepConnection = false;

///

/// Keep the database connection, set to TRUE to provide higher database access performance, but not to ensure that thread is safe. /// public virtual bool KeepConnection {get {return keepConnection;

Set {if (KeepConnection! = Value) {KeepConnection = Value;

IF (KeepConnection == True) {if (connection.state == connectionState.closed) Connection.Open ();} else {connection.close ();}}}}}}}}}}}}}}}}}}}}}}

转载请注明原文地址:https://www.9cbs.com/read-41006.html

New Post(0)