CFLib.org – Common Function Library Project

VerifyDSN(dsn)

Last updated July 1, 2002

author

Ben Forta

Version: 1 | Requires: CF6 | Library: DatabaseLib

Description:
Verifies a DSN is working. It will verify whether the specified DSN is working, not whether it exists. This UDF uses the coldfusion.server.ServiceFactory object.

Return Values:
Returns a Boolean.

Example:

<CFOUTPUT>
Is CFLib.org's main DSN working?: #VerifyDSN("#Request.App.dsn#")#
</CFOUTPUT>

Parameters:

Name Description Required
dsn Name of a DSN you want to verify. Yes

Full UDF Source:

<!---
 Verifies a DSN is working.
 
 @param dsn 	 Name of a DSN you want to verify. (Required)
 @return Returns a Boolean. 
 @author Ben Forta (ben@forta.com) 
 @version 1, October 15, 2002 
--->
<CFFUNCTION NAME="VerifyDSN" RETURNTYPE="boolean">
   <CFARGUMENT NAME="dsn" TYPE="string" REQUIRED="yes">

   <!--- initialize variables --->
   <CFSET var dsService="">
   <!--- Try/catch block, throws errors if bad DSN --->
   <CFSET var result="true">


   <CFTRY>
      <!--- Get "factory" --->
      <CFOBJECT ACTION="CREATE"
                TYPE="JAVA"
                CLASS="coldfusion.server.ServiceFactory"
                NAME="factory">
      <!--- Get datasource service --->
      <CFSET dsService=factory.getDataSourceService()>
      <!--- Validate DSN --->
      <CFSET result=dsService.verifyDatasource(dsn)>

      <!--- If any error, return FALSE --->
	  <CFCATCH TYPE="any">
	     <CFSET result="false">
	  </CFCATCH>
   </CFTRY>

   <CFRETURN result>
</CFFUNCTION>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson