Highlighted

application.cfc error with datasource

Contributor ,
May 20, 2016

Copy link to clipboard

Copied

I am getting an error with my application.cfc file for my database. I am using coldfusion 10 on a windows machine. This application file works on cf 9 and 8 and I do not know what the problem is now. I get the error:

"

Error Occurred While Processing Request

Element DATASOURCE is undefined in APPLICATION."


This is my code and I have tried too make it work 2 ways:

<cfcomponent>

<cfset This.name = "My App">

<cfset This.datasource ="1093644">

<cfset This.clientmanagement="True">

<cfset This.loginstorage="Session">

<cfset This.sessionmanagement="True">

<cfset This.sessiontimeout="#createtimespan(0,0,10,0)#">

<cfset This.applicationtimeout="#createtimespan(5,0,0,0)#">

<cfset THIS.setClientCookies = "1">

<cfset THIS.setDomainCookies = "1">

<cfset THIS.scriptProtect = "All">

<cfsetting showdebugoutput="yes" />

<cffunction name="onApplicationStart" output="false" access="public">

<cfset APPLICATION.EncryptionKey = "S3xy8run3tt3s" />

<cfscript>

  APPLICATION = structNew();

  //site-wide datasource(s)

  APPLICATION.datasource = "1093644";

  strArgs = structNew(); // flush strArgs

  strArgs.datasource = APPLICATION.datasource;

    return true;

  </cfscript>

</cffunction>


I am trying to call it up with my queries like this:

<cfquery name="myQuery" datasource="#APPLICATION.datasource#" dbtype="ODBC">

This is a stupid error and I can't figure it out. I also tried doing this to put the db into the component:

<cfscript>

THIS.name = "myApp";

THIS.datasource = "1093644";

THIS.sessionManagement=true;

THIS.clientManagement=true;

THIS.applicationTimeout = createTimeSpan(0,0,20,0);

THIS.loginStorage = "session";

THIS.sessionTimeout = createTimeSpan(0,0,20,0);

if( isdefined('session') AND structkeyexists(session, 'times_logged_on')

AND session.times_logged_on gte 3 ) THIS.sessiontimeout =

createtimespan(0,0,10,0);

THIS.setClientCookies = 1;

THIS.setDomainCookies = 1;

THIS.scriptProtect = "All";

THIS.secureJSON = false;

THIS.secureJSONPrefix = "";

THIS.mappings = createMappings(pathPrefix="/");

</cfscript>

This app is on a mysql db. If I just use a query with the db name in it, it works. It's not liking my application.cfc code.

Can anyone help me figure out what the issue is? This is also on a shared hosting server.
Thank you.

Adobe Community Professional
Correct answer by BKBK | Adobe Community Professional

APPLICATION = structNew();

That line is incorrect, so delete it. APPLICATION is already defined, as it is an in-built structure in ColdFusion.

TOPICS
Database access

Views

585

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

application.cfc error with datasource

Contributor ,
May 20, 2016

Copy link to clipboard

Copied

I am getting an error with my application.cfc file for my database. I am using coldfusion 10 on a windows machine. This application file works on cf 9 and 8 and I do not know what the problem is now. I get the error:

"

Error Occurred While Processing Request

Element DATASOURCE is undefined in APPLICATION."


This is my code and I have tried too make it work 2 ways:

<cfcomponent>

<cfset This.name = "My App">

<cfset This.datasource ="1093644">

<cfset This.clientmanagement="True">

<cfset This.loginstorage="Session">

<cfset This.sessionmanagement="True">

<cfset This.sessiontimeout="#createtimespan(0,0,10,0)#">

<cfset This.applicationtimeout="#createtimespan(5,0,0,0)#">

<cfset THIS.setClientCookies = "1">

<cfset THIS.setDomainCookies = "1">

<cfset THIS.scriptProtect = "All">

<cfsetting showdebugoutput="yes" />

<cffunction name="onApplicationStart" output="false" access="public">

<cfset APPLICATION.EncryptionKey = "S3xy8run3tt3s" />

<cfscript>

  APPLICATION = structNew();

  //site-wide datasource(s)

  APPLICATION.datasource = "1093644";

  strArgs = structNew(); // flush strArgs

  strArgs.datasource = APPLICATION.datasource;

    return true;

  </cfscript>

</cffunction>


I am trying to call it up with my queries like this:

<cfquery name="myQuery" datasource="#APPLICATION.datasource#" dbtype="ODBC">

This is a stupid error and I can't figure it out. I also tried doing this to put the db into the component:

<cfscript>

THIS.name = "myApp";

THIS.datasource = "1093644";

THIS.sessionManagement=true;

THIS.clientManagement=true;

THIS.applicationTimeout = createTimeSpan(0,0,20,0);

THIS.loginStorage = "session";

THIS.sessionTimeout = createTimeSpan(0,0,20,0);

if( isdefined('session') AND structkeyexists(session, 'times_logged_on')

AND session.times_logged_on gte 3 ) THIS.sessiontimeout =

createtimespan(0,0,10,0);

THIS.setClientCookies = 1;

THIS.setDomainCookies = 1;

THIS.scriptProtect = "All";

THIS.secureJSON = false;

THIS.secureJSONPrefix = "";

THIS.mappings = createMappings(pathPrefix="/");

</cfscript>

This app is on a mysql db. If I just use a query with the db name in it, it works. It's not liking my application.cfc code.

Can anyone help me figure out what the issue is? This is also on a shared hosting server.
Thank you.

Adobe Community Professional
Correct answer by BKBK | Adobe Community Professional

APPLICATION = structNew();

That line is incorrect, so delete it. APPLICATION is already defined, as it is an in-built structure in ColdFusion.

TOPICS
Database access

Views

586

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 20, 2016 0
Adobe Community Professional ,
May 21, 2016

Copy link to clipboard

Copied

APPLICATION = structNew();

That line is incorrect, so delete it. APPLICATION is already defined, as it is an in-built structure in ColdFusion.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 21, 2016 0