Skip to main content
Known Participant
September 26, 2008
Question

Multiple DSN in Application

  • September 26, 2008
  • 4 replies
  • 1106 views
Can I set up multiple DSN in the application.cfc?
This topic has been closed for replies.

4 replies

Astonished_protector15C3
Participating Frequently
October 3, 2008
Hi
Please try the following line of code

<cfcomponent>
<cfparam name="application.error" default="0">

<cfset This.name = "testDSN">
<cfset This.Sessionmanagement="True">
<cfset This.loginstorage="session">
<cfset This.clientmanagement="True">
<cfset This.sessionTimeout=#CreateTimeSpan(0, 1, 0, 0)#>



<cffunction name="OnRequestStart">
<cfargument name = "request" required="true"/>
<cfset application.REQUEST.dsn="test_dsn1">
<cfset application.REQUEST.Reportdsn="test_dsn2">
<cfset application.REQUEST.Commondsn="test_dsn3">
</cffunction>

</cfcomponent>
Inspiring
October 3, 2008
quote:

Originally posted by: V.K.R
Hi
Please try the following line of code

<cfcomponent>
<cfparam name="application.error" default="0">

<cfset This.name = "testDSN">
<cfset This.Sessionmanagement="True">
<cfset This.loginstorage="session">
<cfset This.clientmanagement="True">
<cfset This.sessionTimeout=#CreateTimeSpan(0, 1, 0, 0)#>



<cffunction name="OnRequestStart">
<cfargument name = "request" required="true"/>
<cfset application.REQUEST.dsn="test_dsn1">
<cfset application.REQUEST.Reportdsn="test_dsn2">
<cfset application.REQUEST.Commondsn="test_dsn3">
</cffunction>

</cfcomponent>

Two questions.
1. Why would you set these variables on every page request instead of doing it once when you start the application?
2. Why would you double scope them, ie application.request.something instead of single scoping them, ie application.something?
Inspiring
September 27, 2008
cfdump the request scope. See what you get.

In what function are you setting these variables?
Known Participant
September 30, 2008
I am setting all of these in the Application.cfm
quote:

<cfcomponent output="false">
<cffunction name="onRequestStart" returntype="boolean" output="yes">

<!--- Any variables set here can be used by all our pages --->
<!--- <CFSET request.dataSource = "enroll">--->
<CFSET request.dsn = "test1`">
<CFSET request.dsn2 = "test2">
<CFSET request.companyName = "My Test">
<CFSET ErrorEmail = "cpersone@purdue.edu">

<cfreturn true>
</cffunction>

<!--- Name our application, and enable Application variables --->
<cfset THIS.name = "MyTest">
<cfset THIS.sessionmanagement ="yes">

<!--- Display Custom Message for "Request" Errors --->
<CFERROR TYPE="Request" TEMPLATE="ErrorRequest.cfm" MAILTO="cpersone@purdue.edu">

<!--- Display Custom Message for "Exception" Errors --->
<CFERROR TYPE="Exception" EXCEPTION="Any" TEMPLATE="ErrorException.cfm" MAILTO="cpersone@purdue.edu">

<!--- Display Custom Message for "Validation" Errors --->
<CFERROR TYPE="Validation" TEMPLATE="ErrorValidation.cfm">



<cffunction name="onMissingTemplate" returntype="boolean" output="no">
<cfargument name="targetpage" type="string" required="yes">

<!---log it --->
<cflog file="#THIS.name#" text="Missing Templage: #arguments.targetpage#">
<cflocation url="CF Testing/404.cfm?missingtemplate=#urlEncodedFormat(agruments.targetpage)#" addtoken="no">
</cffunction>
</cfcomponent>
Known Participant
September 30, 2008
Yes i meant cfc. ok I have made the correction for projectdsn. At this point I am more concerend about why I cant get projectdsn to be recognized throughout the site pages.

quote:

<cfcomponent output="false">
<cffunction name="onRequestStart" returntype="boolean" output="yes">

<!--- Any variables set here can be used by all our pages --->
<!--- <CFSET request.dataSource = "Test">--->
<CFSET request.dsn = "test1`">
<CFSET request.projectdsn= "test2">
<CFSET request.companyName = "My Test">
<CFSET ErrorEmail = "cpersone@purdue.edu">

<cfreturn true>
</cffunction>

<!--- Name our application, and enable Application variables --->
<cfset THIS.name = "MyTest">
<cfset THIS.sessionmanagement ="yes">

<!--- Display Custom Message for "Request" Errors --->
<CFERROR TYPE="Request" TEMPLATE="ErrorRequest.cfm" MAILTO="cpersone@purdue.edu">

<!--- Display Custom Message for "Exception" Errors --->
<CFERROR TYPE="Exception" EXCEPTION="Any" TEMPLATE="ErrorException.cfm" MAILTO="cpersone@purdue.edu">

<!--- Display Custom Message for "Validation" Errors --->
<CFERROR TYPE="Validation" TEMPLATE="ErrorValidation.cfm">



<cffunction name="onMissingTemplate" returntype="boolean" output="no">
<cfargument name="targetpage" type="string" required="yes">

<!---log it --->
<cflog file="#THIS.name#" text="Missing Templage: #arguments.targetpage#">
<cflocation url="CF Testing/404.cfm?missingtemplate=#urlEncodedFormat(agruments.targetpage)#" addtoken="no">
</cffunction>
</cfcomponent>


Inspiring
September 26, 2008
What happened when you tried it?
Known Participant
September 26, 2008
Tells me that
Element PROJECTDSN is undefined in REQUEST.
Inspiring
September 26, 2008
yes
Known Participant
September 26, 2008
ok that is what I thought... so I can just do it like this:
<CFSET request.dsn = "enroll">
<CFSET request.projectdsn = "projects">