I am working on building a Windows application that will require a connection to at least two different Microsoft SQL Server databases (for example, a source and a target), which may or may not be on the same server.
So, in the application settings, I would like the user to be able to specify both the server(s) involved, as well as the source and target databases. I did a little bit of research and immediately found this article on Code Project:
http://www.codeproject.com/Articles/31826/SQL-Server-Authentication-using-SMO
It uses something I wasn't previously aware of called, SQL Server Management Objects:
http://msdn.microsoft.com/en-us/library/ms162169(v=sql.105).aspx
Anyway, I am wondering if SMO is the best way to handle establishing connections to data sources that are not known to me, but will be known by the user of the application. Part of the reason I am asking is that most information I am finding seems to be from roughly 5 years ago and want to make sure there isn't a better way to do this today.
Technical Details: I am looking at building it with Windows Forms or as a WPF application and will be dealing with Microsoft SQL Server 2008 R2 and up (likely 2012 and potentially 2014).
Thank you in advance for any advice, thoughts, or suggestions.
Best Answer
If you want to allow users to discover servers/databases on the network SMO is the way to go. If you just want to allow them to enter known (to them) connection information, just collect the information in a form and use a SqlConnectionStringBuilder. Here is a nice article showing how to use it