2
votes

I have created a number of datasources in Lucee using code. This is for a legacy ColdFusion application that we are migrating to Azure, and per the powers-that-be, they want the DSNs created in code so we can store the DSN passwords in a keystore. I have that part already working.

The datasources look something like this: this.datasources["myDSN"]

If, in the code (Application.cfm), I do this:

<cfset myDSN = this.datasources["myDSN"]>

This will then fail:

<cfquery name="whatever" datasource="#myDSN#">

It fails with "datasource myDSN not found."

BUT, if I do this instead:

<cfquery name="whatever" datasource="#this.datasources['myDSN']#">

... it works fine.

Is there a workaround for this? At last check in this one application alone, there are 368 occurrences of datasource= in 115 files. I'd rather not have to do a bulk search/replace. It makes no sense to me that the variable "myDSN" would fail.

As there are multiple datasources being used, I can't just set the default datasource and remove the datasource= attribute entirely; even then, it'd still require a mass search/replace.

I must be missing something. I've read the Lucee docs on datasources but it hasn't helped. Thanks!

1
Are you really using Application.cfm? This could be the cause of your issue. Look into switching to application.cfc - Scott Stroz
It's a legacy app. To give you an idea of just how old it is, there are still instances of "parameterExists()" in it. I'll look into switching, but they're kinda adamant about not making "significant" changes to it. It's one of those Catch 22 situations. :) - RobG
You say the datasources are "created in code". Can you show where and how you are doing that? If you are using Application.cfm, then the this scope isn't available (since it's not a CFC). - CfSimplicity

1 Answers

0
votes

Turns out that Scott Stroz was correct. I switched over to Application.cfc and now it works fine.