/////////////////////////////////////////////////////////////// // This is generated code. ////////////////////////////////////////////////////////////// // Code is generated using LLBLGen Pro version: 2.0.0.0 // Code is generated on: Saturday, February 24, 2007 10:00:22 PM // Code is generated using templates: SD.TemplateBindings.SqlServerSpecific.NET20 // Templates vendor: Solutions Design. // Templates version: ////////////////////////////////////////////////////////////// using System; using System.Data; using System.Data.Common; using System.Data.SqlClient; using System.Configuration; using SD.LLBLGen.Pro.ORMSupportClasses; namespace DataFeedFrameworkDAL.HelperClasses { /// /// General utility methods used for SqlServer usage by the framework. /// public partial class DbUtils { #region Public Static Members public static string ActualConnectionString = string.Empty; #endregion #region Constants private const string connectionKeyString = "DataFeedFrameworkDAL.ConnectionString"; #endregion #region Class Member Declarations private static int _commandTimeOut = 30; #endregion /// /// Private CTor, no instatiation possible /// private DbUtils() { } /// /// Sets the flag to signal the SqlServer DQE to generate SET ARITHABORT ON statements prior to INSERT, DELETE and UPDATE Queries. /// Keep this flag to false in normal usage, but set it to true if you need to write into a table which is part of an indexed view. /// It will not affect normal inserts/updates that much, leaving it on is not harmful. See Books online for details on SET ARITHABORT ON. /// After each statement the setting is turned off if it has been turned on prior to that statement. /// /// Setting this flag is a global change. public static void SetArithAbortFlag(bool value) { SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.ArithAbortOn = value; } /// /// Sets the compatibility level used by the DQE. Default is SqlServer2000. To utilize SqlServer 2005 specific features, set this parameter /// to SqlServer2005, either through a setting in the .config file of your application or by calling this method once in your application. /// Compatibility level influences the query generated for paging, sequence name (@@IDENTITY/SCOPE_IDENTITY()), and usage of newsequenceid() in inserts. /// /// the compatibility level the DQE should be running on. Default is SqlServer 2000 and up. /// Setting the compatibility level is a global change. Calling this method will overrule a similar setting in the .config file. public static void SetSqlServerCompatibilityLevel(SqlServerCompatibilityLevel compatibilityLevel) { SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CompatibilityLevel = compatibilityLevel; } /// /// Creates a new SqlConnection /// /// Conectionstring To use /// A ready to use, closed, sqlconnection object public static SqlConnection CreateConnection(string connectionString) { return new SqlConnection(connectionString); } /// /// Creates a new closed SqlConnection object based on the connection string read from the *.config file of the appdomain. /// The connection string is stored in a key with the name defined in the constant connectionKeyString, mentioned above. /// /// A ready to use, closed, sqlconnection object public static SqlConnection CreateConnection() { if(ActualConnectionString==string.Empty) { ActualConnectionString = ConfigFileHelper.ReadConnectionStringFromConfig( connectionKeyString); } return CreateConnection(ActualConnectionString); } /// /// Determines which connection to use: the connection held by the passed in transaction (if any) or a new one (if no Transaction was passed in) /// /// A transaction the caller participates in. If null, the caller is not participating in a transaction /// A ready to use connection object public static IDbConnection DetermineConnectionToUse(ITransaction containingTransaction) { if((containingTransaction!=null)&&(containingTransaction.ConnectionToUse!=null)) { return containingTransaction.ConnectionToUse; } else { return CreateConnection(); } } /// /// Creates a new SqlDataAdapter. /// /// public static SqlDataAdapter CreateDataAdapter() { return new SqlDataAdapter(); } /// /// Creates a new SqlServer transaction /// /// the connection to use /// the isolation level to use /// the name for the transaction /// new SqlTransaction object. public static SqlTransaction CreateTransaction(IDbConnection connectionToUse, IsolationLevel isolationLevelToUse, string name) { return ((SqlConnection)connectionToUse).BeginTransaction(isolationLevelToUse, name); } /// /// Calls the specified action stored procedure in the SqlServer database a newly created connection is connecting to. /// /// Stored procedure to call /// array of parameters to specify /// the transaction to use, or null if no transaction is available. /// the amount of rows affected. This value will be -1 if the stored procedure sets ROWCOUNT to OFF or this has /// been disabled in the catalog by other settings. public static int CallActionStoredProcedure(string storedProcedureToCall, SqlParameter[] parameters, ITransaction transactionToUse ) { SqlCommand command = null; bool connectionOpenedLocally = false; string procName = SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.GetNewStoredProcedureName(storedProcedureToCall); if(transactionToUse!=null) { command = new SqlCommand(procName, (SqlConnection)transactionToUse.ConnectionToUse); command.Transaction = (SqlTransaction)transactionToUse.PhysicalTransaction; } else { command = new SqlCommand(procName, CreateConnection()); } command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = _commandTimeOut; int toReturn = -1; try { for(int i=0;i /// Calls the specified retrieval stored procedure in the SqlServer database a newly created connection is connecting to. Fills the /// specified datatable. /// /// Stored procedure to call /// array of parameters to specify /// Datatable to fill by the stored procedure /// the transaction to use, or null if no transaction is available. /// true if succeeded, false otherwise public static bool CallRetrievalStoredProcedure(string storedProcedureToCall, SqlParameter[] parameters, DataTable tableToFill, ITransaction transactionToUse) { SqlCommand command = null; string procName = SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.GetNewStoredProcedureName(storedProcedureToCall); if(transactionToUse!=null) { command = new SqlCommand(procName, (SqlConnection)transactionToUse.ConnectionToUse); command.Transaction = (SqlTransaction)transactionToUse.PhysicalTransaction; } else { command = new SqlCommand(procName, CreateConnection()); } command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = _commandTimeOut; SqlDataAdapter adapter = new SqlDataAdapter(command); for(int i=0;i /// Calls the specified retrieval stored procedure in the SqlServer database a newly created connection is connecting to. Fills the /// specified DataSet. /// /// Stored procedure to call /// array of parameters to specify /// DataSet to fill by the stored procedure /// the transaction to use, or null if no transaction is available. /// true if succeeded, false otherwise public static bool CallRetrievalStoredProcedure(string storedProcedureToCall, SqlParameter[] parameters, DataSet dataSetToFill, ITransaction transactionToUse) { SqlCommand command = null; string procName = SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.GetNewStoredProcedureName(storedProcedureToCall); if(transactionToUse!=null) { command = new SqlCommand(procName, (SqlConnection)transactionToUse.ConnectionToUse); command.Transaction = (SqlTransaction)transactionToUse.PhysicalTransaction; } else { command = new SqlCommand(procName, CreateConnection()); } command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = _commandTimeOut; SqlDataAdapter adapter = new SqlDataAdapter(command); for(int i=0;i /// Gets / sets the command time out (in seconds). This is a global setting, so every Command object created after you've set this /// property to a value will have that value as CommandTimeOut. Default is 30 seconds which is the ADO.NET default. /// public static int CommandTimeOut { get { return _commandTimeOut; } set { _commandTimeOut = value; SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CommandTimeOut = _commandTimeOut; } } #endregion #region Included Code #endregion } }