HOME STORE APPLICATIONS COLDFUSION PHP PORTFOLIO PROFILE CONTACT
Maps: TEXT|HTML|XML|RSS

Freelance Web Developer. ColdFusion, PHP, ASP.net programming worldwide

support@cf-works.com. SMS: +7-911-715-57-84

How to get database name in coldfusion by known datasource name? (Item ID:172)

Type:SOFTWARE (downloadable)
Category: Coldfusion Open Source 
Developer:CF-Works   [more items by CF-Works]
Added by:CF-Works   [more items from CF-Works]
Price:FREE
Availability:FREE DOWNLOAD Download How to get database name in coldfusion by known datasource name? for FREE
(Please read CF-Works License Agreement)
Popularity: RateRateRateRateRate

I faced with some problem recently which could not solve by googling. The problem was looking simple: how to get actual database name by coldfusion datasource name? OK in CF 8 Scorpio there is new <cfdbinfo> tag which I thought would work but it does something strange: when tried to query
<cfdbinfo datasource="#REQUEST.ds#" type="dbnames" name="res">
it alphabetically lists all the databases connected to any of datasources instead of retrieving the only database name of the parameter datasource "#REQUEST.ds#". So I had no choice and setup my own solution:
  <CFFUNCTION name="GetDBbyDS" access="remote" returntype="string">
<cfargument name="ds" type="string" required="Yes">
<cfset res="">
<CFIF fileexists("#SERVER.Coldfusion.rootdir#lib eo-datasource.xml")>
<CFFILE action="read" file="#SERVER.Coldfusion.rootdir#lib eo-datasource.xml" variable="wds">
<CFWDDX action="wddx2cfml" input="#wds#" output="resds">
<CFLOOP collection="#resds[1]#" item="c">
<cfif c is ARGUMENTS.ds>
<CFSET curdts=structfind(resds[1],c)>
<CFSET keystostruct=structkeyarray(curdts)>
<CFLOOP from="1" to="#ArrayLen(keysToStruct)#" index="i">
<cfif isstruct(curdts[keysToStruct[i]])>
<cfset res=curdts[keysToStruct[i]]["database"]>
<cfreturn res>
</cfif>
</CFLOOP>
</cfif>
</CFLOOP>
</cfif>
<cfreturn res>
</CFFUNCTION>

This works ok for me and not in CF Scorpio only. Hope this may help someone. - cheers,

 
BRIEF DESCRIPTION: how to get database name from coldfusion datasource


Open/Hide Highlight Group Default downloadable file size

 
write review Add your review to this item:
Existing customers please login (click "Your Account" top menu item).
New customers choose Quick Registration including just your name, email and password or Complete Registration


*Ask a Question about How to get database name in coldfusion by known datasource name?:
E-Mail:enter your email address if you would like to be notified when your question is answered
*Anti-spam code:
Please enter anti-spam code to prevent automated scripts' spam submissions. Thank You

  Status:  
Ready


Reviews Rate: Not Rated
Visitors Rate: RateRateRateRateRate   (1 vote)
Rate this item:
 Rate How to get database name in coldfusion by known datasource name?: how to get database name from coldfusion datasource