coldfusion

ColdFusion datasource within a <cfquery> tag not working


I'm new to ColdFusion. I added a new data source called "coldfusionproject" in CF Administrator. Screenshot of Connected Data Sources in CF Administrator

As you can see, the status is "OK".

However, when I use the datasource = "coldfusionproject" attribute within a <cfquery>, I get the error that states datasource "coldfusionproject" could not be found.

My <cfquery> tag in my code looks like this ("username" and "password" values are actually the values for my local MySQL Server dB):

<cfquery datasource = "coldfusionproject" username = "root" password = "admin">

Any ideas? I'm not sure why it's not finding the data source I created in CF Admin.


Solution

  • I believe I solved my own problem. I created an application.cfc file (thanks @Adam Cameron in the comments), and added this code:

    <cfscript>
    
    component {
    
    this.name = "coldfusionproject";
    
    this.datasources = {
            coldfusionproject = {
    
                database    = "cold_fusion",
                host        = "127.0.0.1",
                port        = "3006",
                driver      = "MySQL5",
                username    = "root",
                password    = "pw"
            }
        };
    
        this.datasource = "coldfusionproject";  
    }
    
    </cfscript>
    

    My app was then able to connect to my local database without errors.