/// <summary> /// Creates an instance of this class. /// </summary> /// <param name="dataSource">Name or IP address of the server.</param> /// <param name="initialCatalog">Name of the database.</param> /// <param name="integratedSecurity">Integrated security. Defaults to true.</param> /// <param name="asynchronousProcessing">Determines whether asynchronous processes is enabled. Defaults to true.</param> /// <exception cref="System.InvalidOperationException"></exception> /// <exception cref="System.Data.SqlClient.SqlException"></exception> /// <exception cref="System.ArgumentException"></exception> public SQLServerDatabase(string dataSource, string initialCatalog, bool integratedSecurity = true, bool asynchronousProcessing = true) { try { _semaphore = new Semaphore(1, 1); _sqlConnection = new SqlConnection(string.Format("Data Source={0};Initial Catalog={1};Integrated Security={2};Asynchronous Processing={3}", dataSource, initialCatalog, integratedSecurity.ToString(), asynchronousProcessing.ToString())) { FireInfoMessageEventOnUserErrors = true, StatisticsEnabled = true }; Open(); _serverVersion = _sqlConnection.ServerVersion; _sqlConnection.ResetStatistics(); Close(); } catch { Close(); throw; } }
// // Constructors // #region Constructors /// <summary> /// Creates an instance of this class. /// </summary> /// <example> /// <code> /// SqlServerDatabase database = new SqlServerDatabase("Data Source=(server name);Initial Catalog=(database name);Integrated Security=True;Asynchronous Processing=True"); /// </code> /// </example> /// <param name="connectionString">Connection string.</param> /// <exception cref="System.InvalidOperationException"></exception> /// <exception cref="System.Data.SqlClient.SqlException"></exception> /// <exception cref="System.ArgumentException"></exception> public SQLServerDatabase(string connectionString) { try { _semaphore = new Semaphore(1, 1); _sqlConnection = new SqlConnection(connectionString) { FireInfoMessageEventOnUserErrors = true, StatisticsEnabled = true }; Open(); _serverVersion = _sqlConnection.ServerVersion; _sqlConnection.ResetStatistics(); Close(); } catch { Close(); throw; } }