Skip navigation
Currently Being Moderated

GetDSN from other method

Jul 10, 2012 8:47 AM

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

 
Replies
  • Currently Being Moderated
    Jul 10, 2012 8:58 AM   in reply to kt03

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 10, 2012 12:25 PM   in reply to kt03

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points