How to I get a list of databases?

How to I get a list of databases?

am 23.07.2007 20:50:32 von Dave Navarro

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

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.

Thanks!

Re: How to I get a list of databases?

am 23.07.2007 21:02:32 von reb01501

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"

Re: How to I get a list of databases?

am 24.07.2007 00:46:40 von Dave Navarro

But don't you have to have permission to access master.dbo.sysdatabases?

I am wondering because if I connect to my ISP's SQL server using
Enterprise Manager, EP will only show me the databases that I own or
have permission to access.

Since I don't have admin rights to their server, I'm wondering how EP
was able to deduce which databases I can access.

--Dave

In article , reb01501
@NOyahoo.SPAMcom says...
> 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.

Re: How to I get a list of databases?

am 24.07.2007 00:52:07 von reb01501

Same permissions quandary, but EM uses the sp_databases system stored
procedure if I am not mistaken.

Dave Navarro wrote:
> But don't you have to have permission to access
> master.dbo.sysdatabases?
>
> I am wondering because if I connect to my ISP's SQL server using
> Enterprise Manager, EP will only show me the databases that I own or
> have permission to access.
>
> Since I don't have admin rights to their server, I'm wondering how EP
> was able to deduce which databases I can access.
>
> --Dave
>
> In article , reb01501
> @NOyahoo.SPAMcom says...
>> 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"