SMO Tips & Tricks: BEWARE the scary Connect option!

So if you are playing around in the SMO codescape you may have noticed the in the server object you have a connect method available …specifically


While it may seems perfectly reasonable that you would want to control the destiny of your connection object…you will want to be wary. The Server Management Objects do a perfectly good job of handling opening and closing of the connection. If you chose to use the Connect method then you have just dumped that responsibility into your own hands. So be sure that if you use it you account for every instance when an error may occur and the connection needs to be closed down gracefully. You have been warned…..