Quick post on how to set up a datasource in the Coldfusion Administrator. First you’ll want to open the Coldfusion Administrator. I’m going to assume that you will be doing this locally since if you don’t have a datasource you’ve probably are just at the beginning stages of development. As such let’s open the admin.
Working locally it is likely that you will use the following link http://localhost:8500/CFIDE/administrator/index.cfm for Coldfusion 8 and http://127.0.0.1:8500/CFIDE/administrator/index.cfm for Coldfusion 9. Remember though if you have multiple versions of the Coldfusion server running on your machine the port number may not be 8500. Instead as ports are used Coldfusion will increment the port number by 1 until reaching the next available port. So for example if you had Coldfusion 8 running, and are now running Coldfusion 9 as well your port number is most likely 8501. Nonetheless, if this is the case, my guess is that your not reading this article.
Once into the administrator click on ‘Data Sources’ under the ‘Data & Services’ tab on the left.
Next create a name for your datasource. This can be whatever you want it to be. This is the label that will represent the connection setup between Coldfusion and this particular database. You will also need to select a driver from the drop-down. In my case I’m using MySql 5 so I’ll choose ‘MySql 4/5′ from the drop-down. You will choose whatever is appropriate for your particular database.
Click ‘Add’ when finished. This will open a new screen requesting more information about your database. The ‘CF Data Source Name’ is the name of the data source you set on the previous screen. It should be prefilled when you get to this page. Next is the name of the actual database. In MySql this will be the name of the Schema holding your tables. If you’re working locally your Server is most likely ‘localhost’ the port will be 3306, and your user name will probably be ‘root’ with no password. I know that using MySql on mac by default is root with no password, but for some reason I’m thinking that on Windows you do set up a password when installing MySql. Don’t quote me on any of this. Long story short, use the same credentials you use to log into MySql via the command line or the GUI Tools. Lastly, you can add a description explaining the data source, but is not required.
I’ll just note that there are a number of advanced settings, but honestly I’ve never had a reason to mess with these. So in all likelihood you shouldn’t either.
Confirm your settings, and you will be taken back to the main Data Sources page. On this page you will get a confirmation in green at the top of the page and ‘OK’ in the ‘status’ on the new line containing the new data source in the list of available data sources on the bottom if the settings were correct.
If not you will receive an error message. I’ve found in my experience that a failed connection is usually due to incorrect username and password. Just remember if you can log into MySql, those same log in credentials will work here.
Hopefully this will be enough to get you a connection between Coldfusion and your database so you can start doing all the fun stuff.