Reputation: 1167
I'm getting an error
The value of the attribute datasource, which is currently '', is invalid.
This happens when I call ApplicationStop() to reset the application. My cfquery calls doesn't have datasource property in it because I've already set it in
this.datasource = "datasourcename"
How can I prevent this error?
Update:
In a script based Application.cfc no error. The error only occurs on a tag based Application.cfc
if the query is in onRequestStart the error says Datasource database could not be found
if the query is in onRequest the error says The value of the attribute datasource, which is currently '', is invalid.
Server info: local Env: CF11 - Production Env: CF 2018
Application.cfc code
<!--- Application name, should be unique --->
<cfset this.name = hash(getbaseTemplatePath())>
<cfset this.datasource = "database">
<!--- Run when application starts up --->
<cffunction name="onApplicationStart" returnType="boolean" output="false">
<cfreturn true>
</cffunction>
<cffunction name="onRequest" returnType="void">
<cfargument name="thePage" type="string" required="true">
<!--- RESET THE APP --->
<cfif isdefined("url.reset" )>
<cfset ApplicationStop() >
<cfset structclear(session)>
<cfhtmlhead text='<script type="text/javascript">alert("Application was refreshed.");</script>'>
</cfif>
<cfquery>
select top 1 * from security_2fa
</cfquery>
<cfinclude template="#arguments.thePage#">
</cffunction>
<cffunction
name="OnRequestStart"
access="public"
returntype="boolean"
output="false"
hint="Fires at first part of page processing.">
<!--- Return out. --->
<cfreturn true />
</cffunction>
Upvotes: 0
Views: 166
Reputation: 1273
Hi @Vlad Thank you for your code here. I've go through your code & it's help more to find an root causes of your issues. Yes I'm also facing the same issue by do test app in my local. The reason is you are did a ApplicationStop() in when your url have "reset". I don't know why you are stop your application here ? Usually we don't stop the any application. Instead we should reinit the application.
Here root cause of your issues is, if you did a applicationStop() then this.name & this.datasource also get stopped or gone.
<cfquery>
select top 1 * from security_2fa
</cfquery>
So once it's stopped then in next line ( Above query ) you have query that don't have any data source name right ? Because it's already stopped or gone :).
<cfquery>
select top 1 * from security_2fa
</cfquery>
<cfif isdefined("url.reset" )>
<cfset ApplicationStop() >
<cfset structclear(session)>
<cfhtmlhead text='<script type="text/javascript">alert("Application was refreshed.");</script>'>
</cfif>
Now you never face the issue. Because your query get executed as before application stop. But you can escape from this issue here only. In case if your arguments.thePage having any other query then you should face the same issue there also. So if you want to stop the application for your scenario then you should do abort ( cfabort ) as soon as stop the application. Like below,
<cfif isdefined("url.reset" )>
<cfset ApplicationStop() >
<cfabort>
</cfif>
Because if you stop the application then you don't want any action or operation or process on your apps.
I can give another suggestion for you, that is you no need to stop the application instead you can do a reinit the application. If you are using fw1 or coldbox or any other framework then use fwreinit option. But if you are working with normal MVC then use my below sample code
<cfif isdefined("url.reset" )>
<cfset onApplicationStart() >
</cfif>
Hope it help you more. Let me know still need any help or clarifications. Thank you !.
Upvotes: 1