none
[PHP][Cloud Services] My web (Azure web app) loses contact with the database after some minutes RRS feed

  • Question

  • Hello everyone.

    I hope some of you can help me; I begin to be desperate.

    My website (Azure web app) loses contact with the BD after several minutes. It does systematically. To resolve momentarily it, I have to restart the Web in Azure (App Service), but after several minutes, the site loses contact with the BD: "Error: unable to establish database connection"

    I checked the passwords and settings in wp-config.php and are correct (in fact, if they were not, they would never be able to see the Web).

    I have also tried to repair the database, but the problem persists.

    Any ideas? I would really appreciate any kind of help in order to to solve the problem.

    Thank you so much in advance.



    Thursday, March 31, 2016 11:43 AM

Answers

  • Hi,

    Thank you for posting here!

    There are many reasons why your website could be having trouble connecting to your database, but they generally fall into three categories:

    1. Database has been corrupted.
    2. Database login credentials are in correct.
    3. Database server is unresponsive.

    These are signs of database corruption:

    WordPress has built-in way to attempt to repair your database, but you’ll have to enable this feature first. To do so, go to wp-config.php file and add this line and save changes.

    define (‘WP_ALLOW_REPAIR’, true);

    This line will enable you to optimize and repair your database.

    Check your database login credentials:

    To do so, open wp-config.php file and cross check login credentials:

     
    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define( 'DB_NAME', 'database_name_here' );
     
    /** MySQL database username */
    define( 'DB_USER', 'username_here' );
     
    /** MySQL database password */
    define( 'DB_PASSWORD', 'password_here' );
     
    /** MySQL hostname */
    define( 'DB_HOST', 'localhost' );

    Often you will notice this error established database connection when your site gets swarmed with a lot of traffic. Basically, user host server just cannot handle the load. And user do not have permissions.

    Test whether your server is running or not by creating a sample script as follows:

    <?php
    $test Connection = mysql_connect('localhost', 'root', 'password');
    if (!$testConnection) {
    die('Error: ' . mysql_error());
    }
    echo 'Database connection working!';
    mysql_close($testConnection);
    ?>

    Create a new file called testconnection.php and paste the following code in it and make sure to replace your credentials and the run. If the connection is successful, that means that your user has sufficient permissions. In case, if it not connected go to wp-config.php and check your credentials.

    In case, database changed or moved, go through wp-config.php add this line:

    $table_prefix = ‘wp_’;

    Hope this helps.

    Regards,

    Pradeep


    Friday, April 1, 2016 5:50 AM

All replies

  • Hi,

    Thank you for posting here!

    There are many reasons why your website could be having trouble connecting to your database, but they generally fall into three categories:

    1. Database has been corrupted.
    2. Database login credentials are in correct.
    3. Database server is unresponsive.

    These are signs of database corruption:

    WordPress has built-in way to attempt to repair your database, but you’ll have to enable this feature first. To do so, go to wp-config.php file and add this line and save changes.

    define (‘WP_ALLOW_REPAIR’, true);

    This line will enable you to optimize and repair your database.

    Check your database login credentials:

    To do so, open wp-config.php file and cross check login credentials:

     
    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define( 'DB_NAME', 'database_name_here' );
     
    /** MySQL database username */
    define( 'DB_USER', 'username_here' );
     
    /** MySQL database password */
    define( 'DB_PASSWORD', 'password_here' );
     
    /** MySQL hostname */
    define( 'DB_HOST', 'localhost' );

    Often you will notice this error established database connection when your site gets swarmed with a lot of traffic. Basically, user host server just cannot handle the load. And user do not have permissions.

    Test whether your server is running or not by creating a sample script as follows:

    <?php
    $test Connection = mysql_connect('localhost', 'root', 'password');
    if (!$testConnection) {
    die('Error: ' . mysql_error());
    }
    echo 'Database connection working!';
    mysql_close($testConnection);
    ?>

    Create a new file called testconnection.php and paste the following code in it and make sure to replace your credentials and the run. If the connection is successful, that means that your user has sufficient permissions. In case, if it not connected go to wp-config.php and check your credentials.

    In case, database changed or moved, go through wp-config.php add this line:

    $table_prefix = ‘wp_’;

    Hope this helps.

    Regards,

    Pradeep


    Friday, April 1, 2016 5:50 AM
  • Hi,

    Per my experience, I think the simple way for installing Wordpress on Azure is thru the Marketplace on Azure new portal.

    There is a good tutorial for getting started for Wordpress on Azure, please see https://azure.microsoft.com/en-us/documentation/articles/web-sites-php-web-site-gallery/.

    You can try to follow the tutorial to do again.

    PRADEEP's answer is great. Thanks for sharing.

    Best Regards.

    Friday, April 1, 2016 7:22 AM
    Moderator

  • Thank you very much for your reply, Pradeep.

    I still continue with the same problems after doing all your suggestions. Let me explain you:


    1. Check database login credentials:

    I cannot see anything wrong here. In fact, if something were wrong, I guess I would NEVER be able to connect to the database. But I do, the website works fine for some minute before the error "unable to establish database connection" appears.

    -------------------

    2. Database repair:

    WordPress is not able to find any error when trying to repair the DB. Here are the results:

    Table wp_users er OK.

    Table wp_usermeta er OK.

    Table wp_posts er OK.

    Table wp_comments er OK.

    Table wp_links er OK.

    Table wp_options is OK.

    Table wp_postmeta is OK.

    Table wp_terms is OK.

    Table wp_term_taxonomy is OK.

    Table wp_term_relationships is OK.

    Table wp_termmeta is OK.

    Table wp_commentmeta is OK

    -------------------

    3.
    Test whether your server is running or not by creating a sample script

    The script page reports: "Database connection working!" even when the website is not able to connect to the database.


    -------------------

    4. Adding the line: "$table_prefix = 'wp_'; 

    The line "$table_prefix = 'wp_';" is already present in the wp-config.php.

    -------------------

    So what do you thing?

    Thank you very much for your help.













    Monday, April 4, 2016 10:01 AM