/// <summary> /// Initializes a new instance of the <see cref="TemporarySqlDatabase"/> class. /// </summary> /// <param name="name">The name.</param> public TemporarySqlDatabase(string name) { databaseName = name; connectionString = string.Format("Server=(local)\\SQLEXPRESS;Database={0};Trusted_connection=true;Pooling=false", databaseName); database = new AdHocSqlRunner(( ) => new SqlConnection(connectionString), "dbo", () => true); var builder = new SqlConnectionStringBuilder(connectionString); builder.InitialCatalog = "master"; master = new AdHocSqlRunner(() => new SqlConnection(builder.ToString()), "dbo", () => true); }
/// <summary> /// Initializes a new instance of the <see cref="TemporarySqlDatabase"/> class. /// </summary> /// <param name="name">The name.</param> public TemporarySqlDatabase(string name) { databaseName = name; connectionString = string.Format("Server=(local);Database={0};Trusted_connection=true;Pooling=false", databaseName); sqlConnection = new SqlConnection(connectionString); database = new AdHocSqlRunner(sqlConnection.CreateCommand, "dbo", () => true); var builder = new SqlConnectionStringBuilder(connectionString) { InitialCatalog = "master" }; masterSqlConnection = new SqlConnection(builder.ToString()); master = new AdHocSqlRunner(() => masterSqlConnection.CreateCommand(), "dbo", () => true); }
/// <summary> /// Initializes a new instance of the <see cref="TemporarySqlDatabase"/> class. /// </summary> /// <param name="name">The name.</param> public TemporarySqlDatabase(string name, string instanceName) { databaseName = name; connectionString = string.Format("Server={0};Database={1};Trusted_connection=true;Pooling=false", instanceName, databaseName); sqlConnection = new SqlConnection(connectionString); database = new AdHocSqlRunner(sqlConnection.CreateCommand, "dbo", () => true); var builder = new SqlConnectionStringBuilder(connectionString) { InitialCatalog = "master" }; masterSqlConnection = new SqlConnection(builder.ToString()); master = new AdHocSqlRunner(() => masterSqlConnection.CreateCommand(), "dbo", () => true); }
/// <summary> /// Initializes a new instance of the <see cref="TemporarySqlDatabase"/> class. /// </summary> /// <param name="name">The name.</param> public TemporarySqlDatabase(string name) { databaseName = name; connectionString = string.Format("Server=(local)\\SQLEXPRESS;Database={0};Trusted_connection=true;Pooling=false", databaseName); database = new AdHocSqlRunner(() => new SqlConnection(connectionString), "dbo", () => true); var builder = new SqlConnectionStringBuilder(connectionString); builder.InitialCatalog = "master"; master = new AdHocSqlRunner(() => new SqlConnection(builder.ToString()), "dbo", () => true); }
/// <summary> /// Initializes a new instance of the <see cref="InMemorySQLiteDatabase"/> class. /// </summary> public InMemorySQLiteDatabase() { var connectionStringBuilder = new SQLiteConnectionStringBuilder { DataSource = ":memory:", Version = 3, DefaultTimeout = 5, JournalMode = SQLiteJournalModeEnum.Memory, UseUTF16Encoding = true }; sharedConnection = new SQLiteConnection(connectionStringBuilder.ConnectionString); sharedConnection.OpenAndReturn(); sqlRunner = new AdHocSqlRunner(() => sharedConnection.CreateCommand(), null, () => true); }
public bool DoesDbExist(string connectionString) { using (SqlConnection connection = new SqlConnection(connectionString)) { string masterConnectionString = this.GetMasterConnectionString(connectionString); string databaseName = this.GetDatabaseName(connectionString); AdHocSqlRunner sqlRunner = new AdHocSqlRunner(() => new SqlConnection(masterConnectionString)).WithVariable("databaseName", databaseName); int countDb = (int)sqlRunner.ExecuteScalar("select count(*) from sys.databases where name = '$databaseName$'"); if (countDb == 1) return true; return false; } }
/// <summary> /// Initializes a new instance of the <see cref="TemporarySQLiteDatabase"/> class. /// </summary> /// <param name="name">The name.</param> public TemporarySQLiteDatabase(string name) { dataSourcePath = Path.Combine(Environment.CurrentDirectory, name); var connectionStringBuilder = new SQLiteConnectionStringBuilder { DataSource = name, Version = 3, DefaultTimeout = 5, JournalMode = SQLiteJournalModeEnum.Memory, UseUTF16Encoding = true }; sqLiteConnection = new SQLiteConnection(connectionStringBuilder.ConnectionString); sharedConnection = new SharedConnection(sqLiteConnection.OpenAndReturn()); sqlRunner = new AdHocSqlRunner(() => sqLiteConnection.CreateCommand(), null, () => true); }
/// <summary> /// Initializes a new instance of the <see cref="InMemorySQLiteDatabase"/> class. /// </summary> public InMemorySQLiteDatabase() { var connectionStringBuilder = new SQLiteConnectionStringBuilder { DataSource = ":memory:", Version = 3, DefaultTimeout = 5, #if MONO JournalMode = SQLiteJournalModeEnum.Off, #else JournalMode = SQLiteJournalModeEnum.Memory, #endif UseUTF16Encoding = true }; ConnectionString = connectionStringBuilder.ToString(); connectionManager = new SQLiteConnectionManager(connectionStringBuilder.ConnectionString); sharedConnection = new SQLiteConnection(connectionStringBuilder.ConnectionString); sharedConnection.Open(); sqlRunner = new AdHocSqlRunner(() => sharedConnection.CreateCommand(), null, () => true); }
/// <summary> /// Verifies the existence of targeted schema. If schema is not verified, will check for the existence of the dbo schema. /// </summary> public void VerifySchema() { if (string.IsNullOrEmpty(Schema)) return; connectionManager().ExecuteCommandsWithManagedConnection(dbCommandFactory => { var sqlRunner = new AdHocSqlRunner(dbCommandFactory, Schema, () => true); sqlRunner.ExecuteNonQuery(string.Format( @"IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = N'{0}') Exec('CREATE SCHEMA [{0}]')", Schema)); }); }
/// <summary> /// Verifies the existence of targeted schema. If schema is not verified, will check for the existence of the dbo schema. /// </summary> public void VerifySchema() { var sqlRunner = new AdHocSqlRunner(connectionFactory, schema); sqlRunner.ExecuteNonQuery(string.Format( @"IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = N'{0}') Exec('CREATE SCHEMA {0}')", schema)); }
/// <summary> /// Verifies the existence of targeted schema. If schema is not verified, will check for the existence of the dbo schema. /// </summary> public void VerifySchema() { if (string.IsNullOrEmpty(Schema)) return; var sqlRunner = new AdHocSqlRunner(connectionFactory, Schema, () => true); sqlRunner.ExecuteNonQuery(string.Format( @"IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = N'{0}') Exec('CREATE SCHEMA {0}')", Schema)); }