Ejemplo n.º 1
0
        public static List <SqlDatabaseSettings> GetSQLDatabasesSettings(string pDatabaseServerName, string pDatabaseLoginName, string pDatabasePassword, bool pintegrated)
        {
            SqlConnection connection = ConnectionManager.GeneralSqlConnection;

            try
            {
                connection.Open();
                SQLInfoEnumerator sie = new SQLInfoEnumerator
                {
                    SQLServer          = pDatabaseServerName,
                    Username           = pDatabaseLoginName,
                    Password           = pDatabasePassword,
                    IntegratedSecurity = pintegrated
                };

                List <SqlDatabaseSettings> list = new List <SqlDatabaseSettings>();
                foreach (string database in sie.EnumerateSQLServersDatabases())
                {
                    SqlDatabaseSettings sqlDatabase = _GetDatabaseInfos(database, connection);
                    if (sqlDatabase == null)
                    {
                        continue;
                    }

                    list.Add(sqlDatabase);
                }

                connection.Close();
                return(list);
            }
            catch (Exception ex)
            {
                connection.Close();
                throw ex;
            }
        }
Ejemplo n.º 2
0
        private static SqlDatabaseSettings _GetDatabaseInfos(string pDatabaseName, SqlConnection pSqlConnection)
        {
            SqlDatabaseSettings sqlDatabase = new SqlDatabaseSettings { Name = pDatabaseName };
            string version = GetDatabaseVersion(pDatabaseName, pSqlConnection);

            if (string.IsNullOrEmpty(version)) return null;

            sqlDatabase.Version = version;
            sqlDatabase.Size = GetDatabaseSize(pDatabaseName, pSqlConnection);
            return sqlDatabase;
        }