I found myself in need of allowing the user to build dynamic connection strings and needed to show the Universal Data Link dialog and retrieve the properties of the connection string that was built. I have noticed a few solutions that use the ADODB library but I think this is a better way:
string
path = AppDomain.CurrentDomain.BaseDirectory + System.DateTime.Now.ToString().Replace("/","").Replace(@"\","").Replace(":","").Replace(" ","")+".udl";
//Create a file stream object that can be pointedly closed. Otherwise, File.Create may not release the process.
FileStream fs = null;
fs = File.Create(path);
fs.Close();
//Keep the process around until we don't need it any longer.
using(Process process = new Process())
{
process.StartInfo.FileName = path;
process.StartInfo.UseShellExecute = true;
process.Start();
while(!process.HasExited);
}
//The stream reader retrieves the connection string.
StreamReader sr = new StreamReader(path);
string contents = sr.ReadToEnd();
sr.Close();
File.Delete(path);
MessageBox.Show(contents);