/// <summary>
        /// This method is used to test a SQL database connection.
        /// </summary>
        public static bool TestDatabaseConnection(SQLDatabaseConnector sqlDatabaseConnector)
        {
            // initial value
            bool connectionAvailable = false;

            try
            {
                // verify the sqlDatabaseConnector exists and the ConnectionString is set
                if ((sqlDatabaseConnector != null) && (!String.IsNullOrEmpty(sqlDatabaseConnector.ConnectionString)))
                {
                    // Open the connection
                    sqlDatabaseConnector.Open();

                    // Test the connection
                    connectionAvailable = sqlDatabaseConnector.Connected;

                    // Close the connection
                    sqlDatabaseConnector.Close();
                }
            }
            catch (Exception error)
            {
                // for debugging only
                string err = error.ToString();
            }

            // return value
            return(connectionAvailable);
        }
Esempio n. 2
0
        /// <summary>
        /// This method loads the Database Schema for the database given.
        /// </summary>
        private void LoadDatabaseSchema(SQLDatabaseConnector connector, ref Database database)
        {
            try
            {
                // if the database exists
                if ((connector != null) && (database != null))
                {
                    // Open the connection
                    connector.Open();

                    // if the connector is open
                    if (connector.Connected)
                    {
                        // Load the database schema
                        connector.LoadDatabaseSchema(database);
                    }

                    // Close the connection
                    connector.Close();

                    // Open the connection
                    connector.Open();
                }
            }
            catch (Exception error)
            {
                // for debugging only
                string err = error.ToString();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// event is fired when the 'GetSchemaHashButton' is clicked.
        /// </summary>
        private void GetSchemaHashButton_Click(object sender, EventArgs e)
        {
            // create a database
            Database database = new Database();

            // paste in your connectionstring
            database.ConnectionString = ConnectionStringControl.Text;

            try
            {
                // if the connecionstring exists
                if (TextHelper.Exists(database.ConnectionString))
                {
                    // Create a new instance of a 'SQLDatabaseConnector' object.
                    SQLDatabaseConnector connector = new SQLDatabaseConnector();

                    // set the connectionstring on the connector
                    connector.ConnectionString = database.ConnectionString;

                    // open the connection
                    connector.Open();

                    // get the schemaHash
                    string schemaHash = connector.GetDatabaseSchemaHash(database);

                    // close the connection
                    connector.Close();

                    // Display the result
                    this.SchemaHashControl.Text = schemaHash;
                }
                else
                {
                    // Show the user a message
                    MessageBoxHelper.ShowMessage("You must paste in a connection string to continue.", "Connectionstring Required");
                }
            }
            catch (Exception error)
            {
                // Show the user a message
                MessageBoxHelper.ShowMessage("An error occurred: " + error.ToString(), "Error");
            }
        }