检查服务器对象是否已连接
我正在使用 Microsoft.SqlServer.Management.Smo
命名空间中的 Server
对象。 我如何检查它是否成功连接到服务器,我看不到与之相关的任何属性。
ServerConnection srvConn = new ServerConnection(server);
// Log in using SQL authentication instead of Windows authentication
srvConn.LoginSecure = false;
// Give the login username
srvConn.Login = serverUserName;
// Give the login password
srvConn.Password = serverPassword;
// Create a new SQL Server object using the connection we created
SqlServer = new Server(srvConn);
我想知道我的用户名和密码的连接是否良好。
感谢您的帮助。
I am working with Server
object from Microsoft.SqlServer.Management.Smo
namespace.
How i can check that it connected successfully to the server i couldnt see there any property related to it .
ServerConnection srvConn = new ServerConnection(server);
// Log in using SQL authentication instead of Windows authentication
srvConn.LoginSecure = false;
// Give the login username
srvConn.Login = serverUserName;
// Give the login password
srvConn.Password = serverPassword;
// Create a new SQL Server object using the connection we created
SqlServer = new Server(srvConn);
I want to know if connection was good with my username and password.
Thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信在您实际使用连接进行某些操作之前,Smo 不会连接到服务器。根据在线书籍:
这意味着您有两个基本策略:
我会说 2 是更好的选择,因为没有确保现在有效的连接将在几秒钟内再次工作:服务器或网络可能会出现故障,或者 DBA 可能会禁用您的登录。从一开始就处理连接失败是使您的应用程序更加健壮的好方法。
I believe that Smo doesn't connect to the server until you actually use the connection for something. According to Books Online:
That means you have two basic strategies:
I would say that 2 is the better option, because there is no guarantee that a connection that works now will work again in a few seconds: the server or network can go down or your login can be disabled by a DBA. Handling connection failures from the beginning would be a good way to make your application more robust.