Developers can create and test a new data source to connect a ColdFusion or Lucee application to a database. This process ensures that the application can successfully communicate with the database before it is used in production.
Before you begin
You will need:
Developer access to the ColdFusion or Lucee Administrator.
Valid database credentials (host, port, username, and password).
The name of the database you wish to connect to.
Create a Data Source
Open the ColdFusion or Lucee Administrator.
Navigate to Data Sources > Add New Data Source.
Enter a unique name for the data source.
Select the appropriate driver for your database (e.g., MySQL, Microsoft SQL Server, or PostgreSQL).
Enter the connection details:
Host: The IP address or hostname of the database server.
Port: The port number the database is listening on.
Username: The database user account.
Password: The password for the database user.
If the connection is successful, click Save.
Test the Data Source
After saving the data source, you must verify it functions correctly within the application environment.
Create a new
.cfmor.cfcfile in your web directory.Add the following code, replacing
YourDataSourceNamewith the name you assigned in the Administrator:<cfdump var="#queryExecute('SELECT 1', 'YourDataSourceName')#">Open the file in a web browser.
If the page displays a result (such as a table containing the value
1), the connection is successful.
If the connection test fails
If the "Test Connection" button in the Administrator fails, check the following:
Network Connectivity: Ensure the database server is reachable from the web server.
Credentials: Verify that the username and password are correct.
Firewall Rules: Ensure the database port is open to the web server's IP address.
Driver Availability: Ensure the correct JDBC driver is installed and enabled in the ColdFusion or Lucee Administrator.
Limitations
The data source name must be unique within the ColdFusion or Lucee instance.
If using a remote database, ensure the database user has permissions to connect from the web server's IP address.
