3 Replies Latest reply: Jul 10, 2012 12:25 PM by Dan Bracuk RSS

    GetDSN from other method

    kt03 Community Member



      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 />



      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" />



          <cfreturn check_duplicate>




        • 1. Re: GetDSN from other method
          Adam Cameron. Community Member

          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.




          • 2. Re: GetDSN from other method
            kt03 Community Member

            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.

            • 3. Re: GetDSN from other method
              Dan Bracuk Community Member

              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.