Пример #1
0
        public static ActionResult CheckSqlServerConnection(Session session)
        {
            session.Log("Start: CheckSqlServerConnection.");

            session["SQL_CONNECTION_ESTABLISHED"] = "1";

            try
            {
                string serverName = GetPropertyStringValue(session, "SQL_SERVER");
                if (string.IsNullOrEmpty(serverName))
                {
                    throw new Exception("Server name is empty. Please enter a correct value.");
                }

                string database = GetPropertyStringValue(session, "SQL_DATABASE");
                if (string.IsNullOrEmpty(database))
                {
                    throw new Exception("Database name is empty. Please enter a correct value.");
                }

                string userName = GetPropertyStringValue(session, "SQL_USER_ID");
                if (string.IsNullOrEmpty(userName))
                {
                    throw new Exception("Login is empty. Please enter a correct value.");
                }

                string password = GetPropertyStringValue(session, "SQL_PASSWORD");
                if (string.IsNullOrEmpty(password))
                {
                    throw new Exception("Password is empty. Please enter a correct value.");
                }

                string connectionString = GetPropertyStringValue(session, "DATABASE_CONNECTION_STRING");
                session.Log("Connection string to SQL Server: {0}", connectionString);

                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();

                    SqlDatabaseValidator databaseValidator = new SqlDatabaseValidator(connection);
                    databaseValidator.Validate(database);

                    SqlDatabasePermissionValidator databasePermissionValidator = new SqlDatabasePermissionValidator(connection);
                    databasePermissionValidator.Validate(database, "CREATE TABLE");
                }
            }
            catch (Exception e)
            {
                InitializeMessageBox(session, e.Message, ERROR_MESSAGE);
                session.Log("Error: {0}; {1};", e.Message, e.StackTrace);
                session["SQL_CONNECTION_ESTABLISHED"] = "0";
            }

            session.Log("Finish: CheckSqlServerConnection.");

            return(ActionResult.Success);
        }
Пример #2
0
        public static ActionResult CheckSqlServerConnection(Session session)
        {
            session.Log("Start: CheckSqlServerConnection.");

            session["SQL_CONNECTION_ESTABLISHED"] = "1";

            try
            {
                string serverName = GetPropertyStringValue(session, "SQL_SERVER");
                if (string.IsNullOrEmpty(serverName))
                {
                    throw new Exception("Server name is empty. Please enter a correct value.");
                }

                string database = GetPropertyStringValue(session, "SQL_DATABASE");
                if (string.IsNullOrEmpty(database))
                {
                    throw new Exception("Database name is empty. Please enter a correct value.");
                }

                string userName = GetPropertyStringValue(session, "SQL_USER_ID");
                if (string.IsNullOrEmpty(userName))
                {
                    throw new Exception("Login is empty. Please enter a correct value.");
                }

                string password = GetPropertyStringValue(session, "SQL_PASSWORD");
                if (string.IsNullOrEmpty(password))
                {
                    throw new Exception("Password is empty. Please enter a correct value.");
                }

                string connectionString = GetPropertyStringValue(session, "DATABASE_CONNECTION_STRING");
                session.Log("Connection string to SQL Server: {0}", connectionString);

                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();

                    SqlDatabaseValidator databaseValidator = new SqlDatabaseValidator(connection);
                    databaseValidator.Validate(database);

                    SqlDatabasePermissionValidator databasePermissionValidator = new SqlDatabasePermissionValidator(connection);
                    databasePermissionValidator.Validate(database, "CREATE TABLE");
                }
            }
            catch (Exception e)
            {
                InitializeMessageBox(session, e.Message, ERROR_MESSAGE);
                session.Log("Error: {0}; {1};", e.Message, e.StackTrace);
                session["SQL_CONNECTION_ESTABLISHED"] = "0";
            }

            session.Log("Finish: CheckSqlServerConnection.");

            return ActionResult.Success;
        }