TestConnection() public static method

Test to see if we can get a successful connection to the DB
public static TestConnection ( ) : DBConnectionStatus
return OSAE.General.DBConnectionStatus
コード例 #1
0
        /// <summary>
        /// Gets an image from the DB
        /// </summary>
        /// <param name="imageId">The id of the image to get</param>
        /// <returns>the requested image</returns>
        public OSAEImage GetImage(int imageId)
        {
            OSAEImage osaeImage = new OSAEImage();

            if (Common.TestConnection())
            {
                using (MySqlConnection connection = new MySqlConnection(Common.ConnectionString))
                {
                    MySqlCommand command = new MySqlCommand("SELECT * FROM osae_images WHERE image_id = " + imageId, connection);
                    connection.Open();

                    MySqlDataReader reader = command.ExecuteReader();

                    if (reader.Read())
                    {
                        osaeImage.ID   = reader.GetUInt32("image_id");
                        osaeImage.Name = reader.GetString("image_name");
                        osaeImage.Type = reader.GetString("image_type");
                        osaeImage.Data = (byte[])reader.GetValue(1);
                    }
                    else
                    {
                        logging.AddToLog("API - Failed to get requested image from DB: " + imageId.ToString(), true);
                    }
                }
            }

            return(osaeImage);
        }
コード例 #2
0
        /// <summary>
        /// Gets all the images available in the DB
        /// </summary>
        /// <returns>returns the images available in the DB</returns>
        /// <remarks>Only call this method if you have to as retrieving all images can take a short while</remarks>
        public List <OSAEImage> GetImages()
        {
            List <OSAEImage> imageList = new List <OSAEImage>();

            if (Common.TestConnection())
            {
                using (MySqlConnection connection = new MySqlConnection(Common.ConnectionString))
                {
                    try
                    {
                        connection.Open();

                        MySqlCommand    command = new MySqlCommand("SELECT * FROM osae_images", connection);
                        MySqlDataReader reader  = command.ExecuteReader();

                        while (reader.Read())
                        {
                            OSAEImage osaeImage = new OSAEImage();
                            osaeImage.ID   = reader.GetUInt32("image_id");
                            osaeImage.Name = reader.GetString("image_name");
                            osaeImage.Type = reader.GetString("image_type");
                            osaeImage.Data = (byte[])reader.GetValue(1);

                            imageList.Add(osaeImage);
                        }
                    }
                    catch (Exception e)
                    {
                        logging.AddToLog("API - GetImages - Failed \r\n\r\n" + e.Message, true);
                    }
                }
            }
            return(imageList);
        }
コード例 #3
0
        /// <summary>
        /// Runs the passed in SQL query on the database and returns a dataset of the results
        /// </summary>
        /// <param name="SQL">The SQL command to be run against the DB</param>
        /// <returns>The Dataset returned from the DB</returns>
        public static DataSet RunQuery(MySqlCommand command)
        {
            DataSet dataset = new DataSet();

            if (Common.TestConnection())
            {
                using (MySqlConnection connection = new MySqlConnection(Common.ConnectionString))
                {
                    MySqlDataAdapter adapter = new MySqlDataAdapter(command);
                    command.Connection = connection;
                    adapter.Fill(dataset);
                }
            }

            return(dataset);
        }
コード例 #4
0
        /// <summary>
        /// Runs the passed in SQL query on the database and returns a dataset of the results
        /// </summary>
        /// <param name="SQL">The sql query to be run against the database</param>
        /// <returns>The dataset returned from the DB</returns>
        public static DataSet RunSQL(string sql)
        {
            DataSet dataset = new DataSet();

            using (MySqlConnection connection = new MySqlConnection(Common.ConnectionString))
            {
                MySqlCommand     command = new MySqlCommand(sql);
                MySqlDataAdapter adapter;

                if (Common.TestConnection())
                {
                    command.Connection = connection;
                    adapter            = new MySqlDataAdapter(command);
                    adapter.Fill(dataset);
                }
            }

            return(dataset);
        }