Thursday, December 22, 2005

Troubleshooting the Dreamweaver MX MySQL Connection

In the guide we look at how to troubleshoot the Dreamweaver MX MySQL Connection. Before we look at troubleshooting the connection, we`ll first look at how the Connection actually works.

How the Dreamweaver MX MySQL Connection Works

To connect to a MySQL database, Dreamweaver MX uploads a hidden file to your server. This code runs on the server, and gets the information about your MySQL database.

Because this code is actually run on your server, rather than your local PC, it will work even if your MySQL server (or hosts) is setup to disallow outside connections.

Once the hidden file has collected information about the MySQL Database Structure and the info it contains, it relays back to Dreamweaver MX. This is why Dreamweaver MX connects to the server when you use the DMX recordset creator for example.

What can go Wrong ?

There are usually only two things that normaly go wrong:

1) Dreamweaver MX uploads its hidden files to the root directory of your web site. If the permissions are set up incorrectly on this directory, then Dreamweaver MX won`t be able to upload the hidden file it uses to connect to the database.

2) Dreamweaver MX can upload the hidden file it needs to connect to the database, but when it goes to read back from the file, it looks in the wrong place on the server.

We`ll now look at how to fix these two problems.

Problem 1 - Dreamweaver MX can`t upload its hidden file

This can be diagnosed by looking at the FTP Log in Dreamweaver MX. To view the FTP Log, you need to open the Results panel, and then select the tab labeledFTP Log.

This log lists all the FTP operations that occur, including the Dreamweaver MX hidden files to connect to the database. If Dreamweaver MX cannot write the files it needs it will tell you here. You then need to change the permissions on your web directory to allow the user who`s FTP details you entered in the Site Definition can upload.

Problem 2 - Dreamweaver MX can upload its hidden file, but can`t read it back

This again can sometimes be diagnosed from the Dreamweaver MX FTP Log, as mentioned for Problem 1. You also need to edit your site definition and check the paths in the Sections shown below:



Local Info Section

Edit the Site Definition for your site, click on the Advanced Tab, and select Local Info from the Category Menu.

Check the path for the HTTP Address. This should be the web path to the root of your web site for example:

http://www.dreamweavermxsupport.com/

Next, you need to check the Testing Server section, which is shown below:



Testing Server Section

First, you need to check that Server Model is set to PHP MySQL.

Next, check the address for the FTP Host is correct.

The next setting, Host Directory, is very important, and is the server path to the root of the web site on the server. For example, on some servers when you log in you are placed in your user directory. In this example to get to the root of the website, we use the server path /web/. If when you log in, you are placed straight in the root of the web directory, then you can leave this box empty.

Next, check your login and password details are correct, and that the user has permission to write to the root of the web site.

Lastly, check the URL Prefix. Again this should be the Web Path to the root of your web site eg

http://www.dreamweavermxsupport.com/

If you entered a path in the Host Directory, this can be appended to the end of the URL Prefix by Dreamweaver MX. This is incorrect, and if it has done this, you need to change it so it points to the root of your web site again.

Check the Dreamweaver MX Database Connection

Open your Dreamweaver MX Database Connection, by clicking the yellow cylinder next to the Database connection name on the Databases tab which is in the Application Panel.



Database Connection Dialog Box

For the MySQL Server, remember that Dreamweaver MX communicates with the Database through a hidden file on the server. This means that for the MySQL server you need to enter localhost rather than the web address of the server, as that`s the context the hidden code is run under.

Finally, Check the User Name and Password are correct, and valid to connect to the MySQL server as a local user. Also check the Database name is correct.

Click the Test button, and your connection should be successful.

Error 401 - Authorisation Error

Another error you may get is a 401 - Authorisation Error, which occurs if your web site is password protected, using an .htaccess file. This means that when Dreamweaver MX uploads its hidden files to get the database information and then tries to read it back, it can`t, because it can`t supply the password so is denied access to the files.

This only occurs if your main website directory is protected, and so by default, every directory underneath is also protected.

This problem is easy to solve. Create a plain text file called .htaccess. Add the following:

satisfy any
allow from all

Save the file, and then upload it into the hidden directory _mmServerScripts which is in the web root directory of your website. This file turns off protection for this directory only, allowing Dreamweaver MX to read the files correctly and will allow you to connect to the database.

No comments: