Skip to main content

How to Create and Test a Data Source

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.

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

  1. Open the ColdFusion or Lucee Administrator.

  2. Navigate to Data Sources > Add New Data Source.

  3. Enter a unique name for the data source.

  4. Select the appropriate driver for your database (e.g., MySQL, Microsoft SQL Server, or PostgreSQL).

  5. 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.

  6. 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.

  1. Create a new .cfm or .cfc file in your web directory.

  2. Add the following code, replacing YourDataSourceName with the name you assigned in the Administrator:

    <cfdump var="#queryExecute('SELECT 1', 'YourDataSourceName')#">

  3. Open the file in a web browser.

  4. 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.

Did this answer your question?