Created
January 3, 2011 15:47
-
-
Save mhayes/763592 to your computer and use it in GitHub Desktop.
List DSN's that exist on a particular server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Server: <cfoutput>#CGI.SERVER_NAME#</cfoutput></h2> | |
<p> | |
The following ColdFusion DSN's are available on this server: | |
</p> | |
<cfscript> | |
// Instantiate CF Admin API | |
adminObj = createObject("component","cfide.adminapi.administrator"); | |
// Pass Login Credentials | |
adminObj.login(adminUserId="<USERNAME>",adminPassword="<PASSWORD>"); | |
// Instantiate DSN ServiceFactory | |
factory = createObject("java", "coldfusion.server.ServiceFactory").DataSourceService; | |
sources = {}; | |
sources = factory.getDatasources(); | |
</cfscript> | |
<table border="1"> | |
<thead> | |
<tr> | |
<th>DSN Name</th> | |
<th>DB Type</th> | |
<th>DB Host</th> | |
<th>DB Username</th> | |
<th>DB SID</th> | |
<th>DB Database</th> | |
<th>DB Description</th> | |
</tr> | |
</thead> | |
<tbody> | |
<cfloop collection="#sources#" item="dsn_name"> | |
<cfset datasource = StructFind(sources,dsn_name) /> | |
<!--- Only display MS-SQL or Oracle Databases ---> | |
<cfif (datasource.DRIVER EQ "MSSQLServer") OR (datasource.DRIVER EQ "Oracle")> | |
<!--- Setup params in case values returned dont exist ---> | |
<cfparam name="datasource.urlmap.VENDOR" default="" /> | |
<cfparam name="datasource.username" default="" /> | |
<cfparam name="datasource.urlmap.CONNECTIONPROPS.HOST" default="N/A" /> | |
<cfparam name="datasource.urlmap.CONNECTIONPROPS.SID" default="N/A" /> | |
<cfparam name="datasource.urlmap.CONNECTIONPROPS.DATABASE" default="N/A" /> | |
<cfparam name="datasource.description" default="N/A" /> | |
<cfoutput> | |
<tr> | |
<td>#dsn_name#</td> | |
<td>#datasource.urlmap.VENDOR#</td> | |
<td>#datasource.urlmap.CONNECTIONPROPS.HOST#</td> | |
<td>#datasource.username#</td> | |
<td>#datasource.urlmap.CONNECTIONPROPS.SID#</td> | |
<td>#datasource.urlmap.CONNECTIONPROPS.DATABASE#</td> | |
<td>#datasource.description#</td> | |
</tr> | |
</cfoutput> | |
</cfif> | |
</cfloop> | |
</tbody> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment