Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 // this method doesn't work on ARM/SQLAzure, use GetDefaultSqlInstance()
 public static List <SqlInstance> RetrieveInstances()
 {
     // use default instance on localhost
     return(SqlInstanceFactory.RetrieveInstances(".", null, true));
 }
Ejemplo n.º 4
0
 // Check if a local SQL server is installed and running on a particular machine
 public static bool IsSqlRunning(string machineName)
 {
     //Log.TraceInternal("Checking for a specific SQL on the machine");
     return(SqlInstanceFactory.RetrieveInstances(machineName, null, true).Count > 0);
 }
Ejemplo n.º 5
0
 // Check if a local SQL server is installed and running
 public static bool IsSqlRunning()
 {
     //Log.TraceInternal("Checking for SQL on the local machine");
     return(SqlInstanceFactory.RetrieveInstances().Count > 0);
 }