The first class of the data access layer (for SQL Server)

zhaozj2021-02-16  50

Data Access Service Class is only available in data access

internal class SQLServer {private SqlConnection connection; private static SQLServer sqlServer; private SqlTransaction sqlTransaction; private bool inTransaction; private SQLServer () {connection = new SqlConnection (GetConnectionString ()); inTransaction = false;} private string GetConnectionString () {string ConnectionString = System.configuration.configurationSettingS.AppSettings ["Connectionstring"]; // If encryption can decrypt Return Connectionstring here;}

///////////////////////////////////////> (Connection == Null) Connection = New SqlConnection (GetConnectionsTRINNECTION); Return connection;}}} // /

/// Open /// public void openconnection () {if (connection.State.toString (). TouPper ()! = "open") connection.open ();} // / /// Close connection /// public void closeconnection () {if (connection.State.toString (). TouPper () == "open") connection.close ();} // / /// transaction /// public sqltransaction sqltran {get {return sqltransaction;}} /// /// Start transaction /// public void begintransaction () { Sqltransaction = connection.begintransaction (); IntraSaction = true;} /// /// Submit transaction /// public void committransaction () {if (sqltransaction! = null) sqltransaction.commit (); INTRANSACTION = false;} /// /// Roll Roll Transaction /// public void RollbackTra NSAction () {if (sqltransaction! = null) sqltransaction.rollback (); IntraSaction = false;} /// /// Get a single object reference /// /// SQLServer Object reference public static sqlserver instance () {if (sqlserver == null) {sqlserver = new SQLServer ();} return sqlserver;}}

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

New Post(0)