public SqlConnection OpenSqlConnection()
        {
            SqlConnection conn = new SqlConnection(_instance.BuildConnectionString(_dbName));

            conn.Open();
            return(conn);
        }
        public static SqlTestDB CreateFromDacpac(InstanceInfo instance, string dacpacPath, DacDeployOptions deployOptions = null, bool dropDatabaseOnCleanup = false)
        {
            string      dbName = Path.GetFileNameWithoutExtension(dacpacPath);
            DacServices ds     = new DacServices(instance.BuildConnectionString(dbName));

            using (DacPackage dp = DacPackage.Load(dacpacPath, DacSchemaModelStorageType.Memory))
            {
                ds.Deploy(dp, dbName, true, deployOptions);
            }
            var sqlDb = new SqlTestDB(instance, dbName, dropDatabaseOnCleanup);

            return(sqlDb);
        }
        public static SqlTestDB CreateFromBacpac(InstanceInfo instance, string bacpacPath, DacImportOptions importOptions = null, bool dropDatabaseOnCleanup = false)
        {
            string      dbName = Path.GetFileNameWithoutExtension(bacpacPath);
            DacServices ds     = new DacServices(instance.BuildConnectionString(dbName));

            using (BacPackage bp = BacPackage.Load(bacpacPath, DacSchemaModelStorageType.Memory))
            {
                importOptions = FillDefaultImportOptionsForTest(importOptions);
                ds.ImportBacpac(bp, dbName, importOptions);
            }
            var sqlDb = new SqlTestDB(instance, dbName, dropDatabaseOnCleanup);

            return(sqlDb);
        }
        public static void ExecuteNonQuery(InstanceInfo instance, string dbName, IList <string> scripts, int commandTimeout = CommonConstants.DefaultCommandTimeout)
        {
            using (SqlConnection conn = new SqlConnection(instance.BuildConnectionString(dbName)))
            {
                conn.Open();

                foreach (string script in scripts)
                {
                    // Replace SqlCmd variables with actual values
                    string exeScript = script.Replace("$(DatabaseName)", dbName);
                    ExecuteNonQuery(conn, exeScript, commandTimeout);
                }
            }
        }
Beispiel #5
0
 public static SqlTestDB CreateFromDacpac(InstanceInfo instance, string dacpacPath, DacDeployOptions deployOptions = null, bool dropDatabaseOnCleanup = false)
 {
     string dbName = Path.GetFileNameWithoutExtension(dacpacPath);
     DacServices ds = new DacServices(instance.BuildConnectionString(dbName));
     using (DacPackage dp = DacPackage.Load(dacpacPath, DacSchemaModelStorageType.Memory))
     {
         ds.Deploy(dp, dbName, true, deployOptions);
     }
     var sqlDb = new SqlTestDB(instance, dbName, dropDatabaseOnCleanup);
     return sqlDb;
 }
Beispiel #6
0
 public static SqlTestDB CreateFromBacpac(InstanceInfo instance, string bacpacPath, DacImportOptions importOptions = null, bool dropDatabaseOnCleanup = false)
 {
     string dbName = Path.GetFileNameWithoutExtension(bacpacPath);
     DacServices ds = new DacServices(instance.BuildConnectionString(dbName));
     using (BacPackage bp = BacPackage.Load(bacpacPath, DacSchemaModelStorageType.Memory))
     {
         importOptions = FillDefaultImportOptionsForTest(importOptions);
         ds.ImportBacpac(bp, dbName, importOptions);
     }
     var sqlDb = new SqlTestDB(instance, dbName, dropDatabaseOnCleanup);
     return sqlDb;
 }
 public static void DropDatabase(InstanceInfo instance, string databaseName, bool displayException = true)
 {
     DropDatabase(instance.BuildConnectionString(CommonConstants.MasterDatabaseName), databaseName, displayException);
 }