Search code examples
coldfusiondatasourcecoldfusion-9

Finding DB info based on Datasource


I am looking to get the DB server and database info from the Datasource name.

I have tried using <cfdbinfo> but it doesn't seem to have any of that information

<cfdbinfo
    type="dbnames"
    datasource="#dsn#"
    name="dbdata">

<cfoutput>
The #dsn# data source has the following databases:<br />
</cfoutput>
<cfdump var="#dbdata#">

I am looking to get the info highlighted in yellowenter image description here


Solution

  • You will need to create an object of the admin API, login and then create an object of the datasource API as follows:

    <cfset admin_api = createObject('component', 'cfide.adminapi.administrator')>
    <cfset admin_api.login('cf_admin_password_here')>
    <cfset admin_api_dsn = createObject('component', 'cfide.adminapi.datasource')>
    

    Then from there you can use the methods exposed by the datasource API to retrieve the information you require.

    Another option would be to read in the file neo-datasource.xml from the {cf_root}/lib/ directory, parse that using xmlparse and then read the data from there.