How do you determine the database of a datasource

Need to work out which database name is associated with a specific datasource.

Do not have access to:

  • web administrator
  • or a password for <cfadmin>

At first I thought <CFDBINFO> would be the ticket :tickets: But it appears it will only give me the list of databases available via the datasource, but not which of the visible databases the datasource is bound to.

For example; the database the datasource is bound to here is stage_boxofbooks but there does not appear to be anyway to tell this programmatically.

<cfdbinfo name="stInfo" type="DBNames" datasource="bob">

A conundrum Iā€™m hoping someone might be able to help with :thinking:

Firstly, a datasource does not require that a database be set. It can be left empty and will end up pointing the default database for the login (at least in SQL Server). If you are ok with some server-specific syntax (and your DB supports it), you can just do a cfquery with this (SQL Server shown)

SELECT db_name()
1 Like

Yikes, sounds scary :scream:

Thanks for that. I was hoping for a DB agnostic approach. Might make a worthwhile enhancement to <CFDBINFO> ā€“ just wish i understood why its not there in the first place.

PS. for any interested parties, mySQL would be: