Re: How to I get a list of databases?



Dave Navarro wrote:
How can I get a list of databases in an SQL server that I have
permissions for?

You can get a list of databases by querying the master.dbo.sysdatabases
table. Depending on the version of SQL Server you are using, there are other
ways as well.

Then, to determine which ones you have permissions for, I guess you would
need to loop through the list of names and attempt to open a connection to
each one in turn, catching the error if it fails.


I have used ADOX to get a list of tables in a database, but I can't
find any sample ADOX code for getting a list of databases on a server
that I can access.

That's because ADOX is geared to work with a single database at a time: its
top-level object is the Catalog, i.e., database.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


.



Relevant Pages

  • Re: Permission to restore databases and access them without being
    ... dbcreator to the login so that you can restore the databases. ... " in SQL Server 2005 Books Online: ... assign your wanted permissions such as db_reader/db_writer ...
    (microsoft.public.sqlserver.security)
  • Re: Hiding database
    ... Jasper Smith (SQL Server MVP) ... >>>Can someone explan how to hide databases in enterprise manager. ... >> permissions are granted to these users. ... > have access rights to one of them. ...
    (microsoft.public.sqlserver.tools)
  • RE: missing system.mdw file
    ... permissions to create the file, ... >The registry key is not missing. ... Running the SCAN program from the Windows ... >>| I cannot create any new databases in Access 2002 on ...
    (microsoft.public.access.setupconfig)
  • Re: Security Script
    ... You when you restore a database, or attach it, SQL Server maintains the ... logins but removes all permissions to databases and their objects. ...
    (microsoft.public.sqlserver.security)
  • Re: one SQL DB getting info from another - user setup?
    ... It appears from your narrative that the Main and DB1 databases ... EXEC sp_helpdb 'Main' ... SQL 2000 SP3 and is turned off by default. ... > In the permissions for Main, USER1 and USER2 are listed, but have NO ...
    (microsoft.public.sqlserver.security)