开发者

How would one List the Databases in a SQL Server, not by query, but by c# call?

From this: Enumerate all running databases

One can list the servers on the network, but once one selects one of those servers, how does one then list the DB's in that server, by using a开发者_开发百科 similar method as above?

Thanks!


You can use SQL Management Objects (SMO). First, you'd use the SmoApplication class and one of its EnumAvailableSqlServers methods to find the server.

Once you've found the server you want, you'd create a Server instance, and then use its Databases property.


Most interactions with a database server eventually translate to SQL. Even if they look like some other API in a higher level. Look for the SQL to do this and just call it from C#

UPDATE: From here

----SQL SERVER 2005 System Procedures
EXEC sp_databases
EXEC sp_helpdb
----SQL 2000 Method still works in SQL Server 2005
SELECT name
FROM sys.databases
SELECT name
FROM sys.sysdatabases
----SQL SERVER Un-Documented Procedure
EXEC sp_msForEachDB 'PRINT ''?'''
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜