Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Datasrouce set in Application cfc

Community Beginner ,
Sep 09, 2008 Sep 09, 2008
I want to set a dataSource in the Application.cfc and then just refer to it in the other pages on the site. How do I set this up? thanks.
TOPICS
Database access
784
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2008 Sep 09, 2008
Set an application variable in the onApplicationStart method.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 09, 2008 Sep 09, 2008
SO something like this
<cffunction name="onRequestStart" returntype="boolean" output="yes">
<CFSET request.dataSource = "enroll">
<cfreturn true>
</cffunction>

Then how do I use it on the other pages?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2008 Sep 09, 2008
TheScarecrow wrote:
> SO something like this
> <cffunction name="onRequestStart" returntype="boolean" output="yes">
> <CFSET request.dataSource = "enroll">
> <cfreturn true>
> </cffunction>
>
> Then how do I use it on the other pages?
>

OnRequestStart is invoked at the start of every request. So it would be
invoked at least once per page, thus setting that variable for you.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2008 Sep 09, 2008
LATEST
like so:

<cfquery name="myquery" datasource="#request.dataSource#">


you could alternatively set the datasource name in application scope in
onAplicationStart function:

<cfset Application.dsn = "mydsn">

then use it on your pages as <cfquery name="myquery"
datasource="#Application.dsn#">

hth

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources