473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

List of SQL-Server Databases

Is it possible to get a list of SQL-Server databases if I know the
server, using C#? I want to provide a drop-down list of them.

Or is there a mechanism for selecting a database?
Nov 16 '05 #1
4 3979
You can do this by executing the T-SQL below using a SqlCommand.

SELECT DbName = [Name] FROM SysDatabases
"Matthew Smith" <ma*****@macxxx.com> wrote in message
news:ma***************************@msnews.microsof t.com...
Is it possible to get a list of SQL-Server databases if I know the
server, using C#? I want to provide a drop-down list of them.

Or is there a mechanism for selecting a database?

Nov 16 '05 #2
oj
Sure. All you need is to create a connection to the sqlserver and execute
this t-sql.

SELECT CATALOG_NAME
FROM INFORMATION_SCHEMA.SCHEMATA
WHERE has_dbaccess(CATALOG_NAME) = 1

I would highly recommend using this instead of hitting the system table
(sysdatabases) directly. This statement would do 3 things for you.
1. It takes care of security issue - it only returns the name of the
database that the user has access to.
2. It's ANSI compliant.
3. It will work in the next version of sqlserver.
--
-oj
"Matthew Smith" <ma*****@macxxx.com> wrote in message
news:ma***************************@msnews.microsof t.com...
Is it possible to get a list of SQL-Server databases if I know the
server, using C#? I want to provide a drop-down list of them.

Or is there a mechanism for selecting a database?

Nov 16 '05 #3
But for both the solutions you will need the sa (Sys Admin) login or a
login that has access to all the databases(which is not a good thing to
do ) ..... so that you can list all the databases on the server

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
oj
I beg your pardon.

You do not need 'sa' account to execute the query. Have you even tried.

--
-oj
"Shinva" <shinva> wrote in message
news:uV**************@tk2msftngp13.phx.gbl...
But for both the solutions you will need the sa (Sys Admin) login or a
login that has access to all the databases(which is not a good thing to
do ) ..... so that you can list all the databases on the server

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Shea | last post by:
Hi - I've writing a Python script which has a query which looks like this ... select * from T where C1 not in (1,2,3) .... C1 is a numeric column so elements of (1,2,3) must not be quoted...
0
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the...
6
by: calan | last post by:
Relative SQL newbie here......this is probably easy, but.... Lets say I have a table (MainTable) that stores a list of input table names, a primary key (PKey), and a field called "Configured" for...
6
by: Dave Hopper | last post by:
Hi I am using the following SQL to retrieve a value in a list box using a unique ID held in the list box call cntID. The list box is used on an order form to list appointments that have been...
0
VbaNewbee
by: VbaNewbee | last post by:
I have a form with a few filters. Once the user clicks "search button", the code first evaluates my filters, then shows the query results in a List Box" titled backschedule. I have a few text...
4
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be...
8
by: Andy | last post by:
Hi, I'm trying to add a where clause to my query: List<stringtypes = new List<string>(); types.Add( "A" ); types.Add( "B" ); query = query.Where( c =types.Contains( c.Type ) );
3
by: rewonka | last post by:
Hello, I'm trying to find the fastest way to convert an sql result into a dict or list. What i mean, for example: my sql result: contact_id, field_id, field_name, value sql_result=, , ,
12
by: Gilles Ganault | last post by:
Hello I'm getting some unwanted result when SELECTing data from an SQLite database: ====== sql = 'SELECT id FROM master' rows=list(cursor.execute(sql)) for id in rows: sql = 'SELECT...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.