Skip to main content
Inspiring
July 10, 2012
Question

GetDSN from other method

  • July 10, 2012
  • 1 reply
  • 1018 views

Hi,

can some one tell me how to call the dsn from other method within the same cfc.

this getDSN method return me the correct dsn that i declared from application.cfm.

<cffunction name="GetDSN" access="public"  output="false"    hint="Gets the DSN">

<cfargument name="dsn" required="yes">

    <cfreturn this />

</cffunction>

how can i get the dsn from above method.  What i have is not working..........

<cffunction name="findDupicate" output="no" access="public" returntype="query">

        <cfargument name="form" required="yes" type="struct">   

        <cfquery name="check_duplicate" datasource="#GetDSN#">

        SELECT voucherNo

        FROM voucher

        WHERE voucherNo= <cfqueryparam value="#arguments.form.voucher#" cfsqltype="cf_sql_varchar" />

       

    </cfquery>

    <cfreturn check_duplicate>

    </cffunction>

Thanks

This topic has been closed for replies.

1 reply

Inspiring
July 10, 2012

Two things that immediately spring to mind.

getDsn() is misnamed, or does the wrong thing.  It doesn't return a DSN, it returns the entire object (return this).

I your CFQUERY tag you're not calling getDsn(), you're just using it as a value, eg: "getDsn" is a reference to the method itself, but "getDsn()" is actually CALLING the method.

Oh a third thing: something called getDsn() would not normally take an argument that is the very thing it is supposedly getting.  IE: why is getDsn() taking an argument of dsn?  It should be RETURNING the DSN name, not having it passed into it.

--

Adam

kt03Author
Inspiring
July 10, 2012

the reason i have have argument because it was set in application.cfm page.

<cfobject type="component" name="request.voucher" component="#request.cfc#.voucher">

<cfset variables.dsn = request.voucher.GetDSN(#DBSource#) />

i have try calling getDSN(), but got this and don't know what to pass it in?

The DSN parameter to the GetDSN function is required but was not passed in.

Inspiring
July 10, 2012

You may be overengineering things.  If variables.dsn is set in your application.cfm file, you should be able to simply use that variable in your cfquery tag.