如何测试SqlServer的连接,而无需打开一个数据库数据库、测试、SqlServer

2023-09-05 00:34:27 作者:超人不会飞

标题pretty的多少说明了一切。我想创建一个SqlConnection,然后检查没有在这一点上我还不知道会在哪里我连接到打开数据库,导致该连接。是否有可能这样做吗? SqlConnection类有一个打开部件,它试图打开你的数据库属性中设置的数据库,如果您没有设置之一,SqlServer的尝试与主数据库。问题是,我试图用(MACHINE \ ASPNET)连接访问某些数据库(我还不知道)用户,而不是主数据库。

The title pretty much says it all. I want to create a SqlConnection and then check that connection without opening a database, cause at that point I don't know yet where will I connect to. Is it possible to do that? The SqlConnection class has a 'Open' member which tries to open the database you'd set in the Database property, and if you didn't set one, SqlServer tries with the master db. The thing is the user I'm trying to connect with (MACHINE\ASPNET) has access to some databases (which I don't know yet) and not the master db.

问候, 西巴

推荐答案

连接到临时数据库。每个人都有accecss到tempdb中,所以你就可以验证自己的访问。后来,当你知道实际的数据库,你可以改变这个属性来连接到您需要的分贝。

Connect to temp db. Everybody has accecss to tempdb so you will be able to authenticate yourself for access. Later when you know the actual database , you can change this property to connect to the db you want.