Results 1 to 5 of 5

Thread: SQL Server - Current Database

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Resolved SQL Server - Current Database

    Is there anyway, using ADO (2.6) or T-SQL (SQL Server 2000) to find out the current database when you are connected?
    Last edited by simonm; May 23rd, 2005 at 08:51 AM.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL Server - Current Database

    Quote Originally Posted by simonm
    Is there anyway, using ADO (2.6) or T-SQL (SQL Server 2000) to find out the current database when you are connected?
    Isn't it sitting in text in the CONNECTION STRING? Didn't you build the connection string in code?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: SQL Server - Current Database

    Quote Originally Posted by szlamany
    Isn't it sitting in text in the CONNECTION STRING? Didn't you build the connection string in code?
    For the particular application I am building, the user can select which database he wishes to use. However, when connecting to a server, each login may have a default database.

    I simply need to be able to query the connection to find out what my current database context is...
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  4. #4
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016

    Re: SQL Server - Current Database

    Use the db_name() function:
    Code:
    Select db_name()
    That will return the name of the current database.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  5. #5

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: SQL Server - Current Database

    Thanks vb_dba!
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width