I’m having a random error where cfquery is not usi...
# cfml-general
d
I’m having a random error where cfquery is not using the global datasource name defined in my Application.cfc file. I have a datasource defined using this.datasource, but occasionally (fairly frequently lately), ACF throws a “The value of the attribute datasource, which is currently ‘’, is invalid.” error for random cfquery tags that have no datasource attribute and only the name attribute defined. <cfquery name=“myQuery”> Any ideas as to what might be causing this and how to fix it? Also, this is a site that has been running for over a decade on CF and primarily uses Hibernate and ORM. CF version 2018,0,13,329786
r
Hi Dean, just curious if the random errors happen to be centralized to a specific cfquery or two when it happens or does this randomly happen to many cfqueries across the application?
d
Hi Jim. I thought that it was primarily a single query, which I rewrote to use Hibernate. This fixed the issue for that query, but another query last night threw the exact same error.
Oh, and it’s not consistent. That query is used throughout the day with no problem. It just occasionally that the error is thrown.
a
Are you using
cfquery
tag or
new Query()
syntax
Is the query in a CFC which is a singleton?
d
cfquery, and yes, it is a singleton CFC
a
Is the name you're using
var
scoped?
Copy code
<cfset var meh = "">
<cfquery name="meh">
...
</cfquery>
"occasionally that the error is thrown" hints at a race condition, so unscoped variables could well be the culprit
👍🏼 1
d
Hmm, interesting. Looking at the query that threw the query last night, it is not var scoped. I will update that to see if it fixes the issue. Thanks!
I’m looking through the site code at other cfquery tags in CFC singletons and they are all var scoped. It is just these couple of queries that are not.,so that is probably the issue. Thanks, again!
👍🏼 1
👍 2
a
Get cflint - dead handy for flagging these things
a
TBH, I think yer on a wild goose chase looking at the query objects if the issue is a disappearing application setting.
👍 1
My bet would be that you are switching applications occasionally, to one that doesn't have a datasource set in its metadata.
Do you have any other Application.cfc files in the app, or
<cfapplication>
tags anywhere?
Are there any other CFML applications running on that server?
d
Hey Adam. Yes, I do have other Application.cfc files, but as far as I know, they all share the same application name. I will have to double check. And also yes, I do have other sites running CF on the same server. But they too should have unique application names.
a
"sharing the same application name" is your problem
Unless they are the same application, they should not have the same name
And I suspect one of those other applications doesn't have
this.datasource
set, right?
d
I am using Taffy for my REST API and I think that that may be the issue. Upon closer inspection, it uses a super.onApplication call and I think that I was under the impression that it was calling the Application.cfc in the root because of the shared application name. However, I now see that it is actually extending Taffy’s main CFC. So I think that you are right, that if the API is called before the main site, the datasource name is not being set for the application.
1