private bool IsMeetingFilterCriteria(SqlInstance sqlInstance) { bool bRet = true; do // do while(false) to allow break - readability { if (string.Compare(this.MachineName, sqlInstance.ServerHostName, true) != 0) { bRet = false; break; } if ((_defaultInstanceFilter != null) && (sqlInstance.IsDefault != _defaultInstanceFilter)) { bRet = false; break; } if ((_expressEditionFilter != null) && (sqlInstance.IsExpressEdition != _expressEditionFilter)) { bRet = false; break; } }while (false); return(bRet); }
public static SqlInstance CreateCustomDatabase(string DatabaseName) { SqlInstance instance = new SqlInstance(); instance.CreateDatabase(DatabaseName); instance.SetDatabase(DatabaseName); DatabaseConfiguration dbConfig = DatabaseConfigurations.SqlPersistenceConfiguration(InstanceStoreVersion.Version45); instance.ExecuteSqlFile(dbConfig.CreateSchema); instance.ExecuteSqlFile(dbConfig.CreateLogic); return(instance); }
public static string GetDefaultSqlServerName() { //if (TestParameters.IsSqlAzureRun || TestParameters.IsArmRun) //{ // //As this is an azure run extracting default sql Server Name from ConnectionString // string connString = TestParameters.SqlPersistenceConnectionString; // SqlConnection connection = new SqlConnection(connString); // return connection.DataSource.ToString(); //} SqlInstance defaultSqlInstance = GetDefaultSqlInstance(); return((defaultSqlInstance != null) ? defaultSqlInstance.MasterConnection.DataSource : "localhost");//PartialTrustEnvironment.GetMachineName(); }
protected virtual void Dispose(bool disposing) { if (_disposed == false) { if (disposing) { if (sqlInstance != null) { this.sqlInstance.Dispose(); sqlInstance = null; } } _disposed = true; } }
public static SqlInstance GetDefaultSqlInstance() { //if (TestParameters.IsSqlAzureRun || TestParameters.IsArmRun) //{ // //Log.TraceInternal("Detected SQL Azure or ARM run, using SqlPersistenceConnectionString (" + TestParameters.SqlPersistenceConnectionString + ") directly"); // return new SqlInstance(TestParameters.SqlPersistenceConnectionString); //} SqlInstance defaultSqlInstance = null; List <SqlInstance> sqlInstances = SqlInstanceFactory.RetrieveInstances("localhost", null, true); if (sqlInstances != null && sqlInstances.Count > 0) { defaultSqlInstance = sqlInstances[0]; } return(defaultSqlInstance); }
public SqlProviderHelper(string databaseName, string connString, DatabaseConfiguration dbConfig) { if (string.IsNullOrEmpty(databaseName) && string.IsNullOrEmpty(connString)) { throw new ArgumentNullException("databaseName", "'databaseName' cannot be null if 'connString' is null"); } this.dbConfig = dbConfig; if (!string.IsNullOrEmpty(connString)) { this.sqlInstance = new SqlInstance(connString); // if the 'Initial Catalog value' is not specified we try to use the databaseName. If databaseName is null, then we throw. if (string.IsNullOrEmpty(this.sqlInstance.DatabaseName)) { if (string.IsNullOrEmpty(databaseName)) { throw new ArgumentNullException("connString", "must specify a 'Initial Catalog' value or use the databaseName parameter"); } this.databaseName = databaseName; } else { this.databaseName = this.sqlInstance.DatabaseName; } } else // They didn't specify a connString, so grab the first instance on the localhost { this.databaseName = databaseName; List <SqlInstance> sqlInstances = SqlInstanceFactory.RetrieveInstances("localhost", null, true); if (sqlInstances != null && sqlInstances.Count > 0) { this.sqlInstance = sqlInstances[0]; } else { throw new Exception("Unable to retrieve Sql Instance, check to ensure Sql is installed"); } } this.sqlInstance.SetDatabase(this.databaseName); }