Ejemplo n.º 1
0
        // check login
        public static DatabaseConnectionResult CheckSqlLogin(string dbServer, string dbUsername, string dbPassword)
        {
            DatabaseConnectionResult dbConnectResult = new DatabaseConnectionResult();

            // check password for characters that are not supported in a connection string
            Match match = Regex.Match(dbPassword, @"[,;(){}\[\]]", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                // we have an illegal character
                dbConnectResult.CanConnect = false;
                dbConnectResult.Message    = "Please do not use one of the following characters in your database password '[] {}() , ; ? * ! @'.";
            }
            else
            {
                // setup connection
                string        connectionString = String.Format("user id={0};password={1};server={2};connection timeout=4", dbUsername, dbPassword, dbServer);
                SqlConnection testConnection   = new SqlConnection(connectionString);

                // try connection
                try
                {
                    testConnection.Open();
                    dbConnectResult.CanConnect = true;
                    dbConnectResult.Message    = String.Format("The user {0} connected successfully to {1}.", dbUsername, dbServer);
                }
                catch (Exception ex)
                {
                    dbConnectResult.CanConnect = false;
                    dbConnectResult.Message    = String.Format("The user {0} could not connect to the server {1}. Error message: {2}.", dbUsername, dbServer, ex.Message);
                }
                finally
                {
                    testConnection = null;
                }
            }



            return(dbConnectResult);
        }
        // check login
        public static DatabaseConnectionResult CheckSqlLogin( string dbServer, string dbUsername, string dbPassword )
        {
            DatabaseConnectionResult dbConnectResult = new DatabaseConnectionResult();

            // check password for characters that are not supported in a connection string
            Match match = Regex.Match( dbPassword, @"[,;(){}\[\]]", RegexOptions.IgnoreCase );
            if ( match.Success ) 
            {
                // we have an illegal character
                dbConnectResult.CanConnect = false;
                dbConnectResult.Message = "Please do not use one of the following characters in your database password '[] {}() , ; ? * ! @'.";
            }
            else
            {
                // setup connection
                string connectionString = String.Format( "user id={0};password={1};server={2};connection timeout=4", dbUsername, dbPassword, dbServer );
                SqlConnection testConnection = new SqlConnection( connectionString );

                // try connection
                try
                {
                    testConnection.Open();
                    dbConnectResult.CanConnect = true;
                    dbConnectResult.Message = String.Format( "The user {0} connected successfully to {1}.", dbUsername, dbServer );

                }
                catch ( Exception ex )
                {
                    dbConnectResult.CanConnect = false;
                    dbConnectResult.Message = String.Format( "The user {0} could not connect to the server {1}. Error message: {2}.", dbUsername, dbServer, ex.Message );
                }
                finally
                {
                    testConnection = null;
                }
            }

            

            return dbConnectResult;
        }
Ejemplo n.º 3
0
        // check sql server
        public static EnvironmentCheckResult CheckSqlServer(string dbServer, string dbUsername, string dbPassword, string dbDatabase)
        {
            EnvironmentCheckResult result = new EnvironmentCheckResult();

            result.Message = "Your database settings all look good.";
            result.DidPass = true;

            // check that user can login
            DatabaseConnectionResult connectResult = CheckSqlLogin(dbServer, dbUsername, dbPassword);

            if (!connectResult.CanConnect)
            {
                result.Message = connectResult.Message;
                result.DidPass = false;
                return(result);
            }

            // check sql version
            DatabaseConfigurationResult sqlVersionResult = CheckSqlServerVersion(dbServer, dbUsername, dbPassword);

            if (!sqlVersionResult.Success)
            {
                result.Message  = string.Format("You are running SQL Server version: {0}", sqlVersionResult.Message);
                result.HelpLink = "http://www.rockrms.com/Rock/LetsFixThis#SqlServerWrongVersion";
                result.DidPass  = false;
                return(result);
            }

            // check if database exists
            if (!CheckSqlDatabaseExists(dbServer, dbUsername, dbPassword, dbDatabase))
            {
                // try creating the database
                if (!CheckSqlPermissionsCreateDatabase(dbServer, dbUsername, dbPassword))
                {
                    result.Message  = String.Format("The database '{0}' does not exist and the user '{1}' does not have permissions to create a database.", dbDatabase, dbUsername);
                    result.HelpLink = "http://www.rockrms.com/Rock/LetsFixThis#NoDatabaseNoPermissions";
                    result.DidPass  = false;
                    return(result);
                }

                result.Message = String.Format("The '{0}' database does not exist on the server, but you have permissions to create it.  Rock will create it for you as part of the install.", dbDatabase);
            }
            else
            {
                // check that we have permissions to create a table in the database
                if (!CheckSqlPermissionsCreateTable(dbServer, dbUsername, dbPassword, dbDatabase))
                {
                    result.Message  = String.Format("The user '{0}' does not have write access to the database '{1}'.", dbUsername, dbDatabase);
                    result.HelpLink = "http://www.rockrms.com/Rock/LetsFixThis#SqlServerPermissions";
                    result.DidPass  = false;
                    return(result);
                }

                // since the database exists make sure it's empty
                if (!CheckSqlServerEmpty(dbServer, dbUsername, dbPassword, dbDatabase))
                {
                    result.Message  = String.Format("The database '{0}' is not empty. To protect your existing data Rock must be installed into a empty database.", dbDatabase);
                    result.HelpLink = "http://www.rockrms.com/Rock/LetsFixThis#DatabaseNotEmpty";
                    result.DidPass  = false;
                    return(result);
                }
            }

            DatabaseConfigurationResult sizeResult = CheckSqlDatabaseSize(dbServer, dbUsername, dbPassword, dbDatabase);

            if (!sizeResult.Success)
            {
                result.Message  = sizeResult.Message;
                result.HelpLink = "http://www.rockrms.com/Rock/LetsFixThis#DatabaseTooSmall";
                result.DidPass  = false;
                return(result);
            }

            return(result);
        }
Ejemplo n.º 4
0
        // check login
        public static DatabaseConnectionResult CheckSqlLogin( string dbServer, string dbUsername, string dbPassword )
        {
            DatabaseConnectionResult dbConnectResult = new DatabaseConnectionResult();

            // setup connection
            string connectionString = String.Format( "user id={0};password={1};server={2};connection timeout=10", dbUsername, dbPassword, dbServer );
            SqlConnection testConnection = new SqlConnection( connectionString );

            // try connection
            try
            {
                testConnection.Open();
                dbConnectResult.CanConnect = true;
                dbConnectResult.Message = String.Format( "The user {0} connected successfully to {1}.", dbUsername, dbServer );

            }
            catch ( Exception ex )
            {
                dbConnectResult.CanConnect = false;
                dbConnectResult.Message = String.Format("The user {0} could not connect to the server {1}. Error message: {2}.", dbUsername, dbServer, ex.Message);
            }
            finally
            {
                testConnection = null;
            }

            return dbConnectResult;
        }