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.
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.