我如何从Sql服务器读取所有数据库 [英] how i can read all database from Sql sever

查看:68
本文介绍了我如何从Sql服务器读取所有数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有





请告诉我如何在我的vb.net应用程序中读取所有sql server数据库组合框

以及如何与sql数据库进行手动连接时,如果应用程序属性为vb.net

解决方案

简单连接并添加该查询。



SELECT name FROM master..sysdatabases



运行此查询您的Sql Server并获取所有数据库。


读取所有数据库名称:

 使用 con 作为  SqlConnection( 数据源= GRIFFPC\SQLEXPRESS;集成安全性=真
con.Open()
使用 cmd 作为 SqlCommand( sp_databases,con)
cmd.CommandType = CommandType.StoredProcedure
Dim 读取作为 SqlDataReader = cmd.ExecuteReader()
while read.Read()
Console.WriteLine( DirectCast (读取(< span class =code-string> DATABASE_NAME), String ))
结束
结束 使用
结束 使用



您的其他问题更难回答 - 您所要做的就是设计一个至少包含服务器名称,用户名和密码字段的表单,以及哪个返回连接字符串,但这不是非常用户友好,可能不是你想要的。请记住,不同的数据库可以拥有不同的用户和不同的密码...



打开SSMS,出现的第一个屏幕可能是你要复制的 - 是任何部分那给你一个问题?


Dear All


kindly please tell me how i can read all database of sql server in my application of vb.net in combo box
and how i can make manual connection with sql database it ask server and database and user name password always when application stat of vb.net

解决方案

Simple Connection and Add THis Query.

SELECT name FROM master..sysdatabases

Run this Query youe Sql Server And Get ALL Database.


To read all database names:

Using con As New SqlConnection("Data Source=GRIFFPC\SQLEXPRESS;Integrated Security=True")
	con.Open()
	Using cmd As New SqlCommand("sp_databases", con)
		cmd.CommandType = CommandType.StoredProcedure
		Dim read As SqlDataReader = cmd.ExecuteReader()
		While read.Read()
			Console.WriteLine(DirectCast(read("DATABASE_NAME"), String))
		End While
	End Using
End Using


Your other question is harder to answer - all you have to do is design a form which contains a server name, a user name, and a password field at the minimum, and which returns a connection string, but that really isn''t very user-friendly, and probably isn''t exactly what you want. Remember that different databases can have different users, and different passwords...

Open SSMS and the first screen which appears is probably what you want to duplicate - is any part of that giving you a problem?


这篇关于我如何从Sql服务器读取所有数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆