A)
http://stackoverflow.com/questions/4701779/check-for-live-data-source-name-before-proceeding
I like Sean Coyne's comment about using the API (iow, just use the same cfc method that the administrator uses).

B)
Another contending argument goes something like: "why don't you just DO the SQL you wanted to do in the first place, and if it fails then roll back any transaction (TX), inform the user, and then 'not attempt anything else.' ?  Why waste a DB connection & query on a 'test' that a real process could equally perform? JDBC connections and database processes could easily be lost midway through a TX, so this pre-test would just be another layer, on top of properly coded TX recovery anyway".

Hopefully, either passage can help you.
Al

On 11/13/2014 11:01 AM, Jason Allen wrote:
I have a few functions that I'd like to verify datasource health before attempting further code. 

Ideally, I'd have a function like 'dataSourceIsAvailable('datasourceName') that would return true/false

If true, I would attempt some database oriented code. If false, I would throw error and not attempt anything else. 

So far, this is the best I can come up with. I would rewrite this into a function with DSN and tableName as arguments.


<cftry>

  <cfquery name="dbcheck" datasource="myDSN">
    select top 1 * from TABLE
  </cfquery>
  
  <!--- specify the type of error for which we search --->

  <cfcatch type = "Database">
    <cfif #cfcatch.message# contains 'Error'>
      <cfset dbERROR = 1>
      <cfabort>
    </cfif>
  </cfcatch>

</cftry>

--
--
online documentation: http://openbd.org/manual/
http://groups.google.com/group/openbd?hl=en

---
You received this message because you are subscribed to the Google Groups "Open BlueDragon" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

--
--
online documentation: http://openbd.org/manual/
http://groups.google.com/group/openbd?hl=en

---
You received this message because you are subscribed to the Google Groups "Open BlueDragon" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to