Blog Stats
  • Posts - 178
  • Articles - 0
  • Comments - 139
  • Trackbacks - 172

 

A better way to launch the Data Connection Properties dialog box

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);


Feedback

# re: A better way to launch the Data Connection Properties dialog box

Gravatar Hi,
why do you think, that this is an advantagous approach?

Your app still depends on ADODB, because otherwise the connection dialog cannot be shown.

Your code requires file IO permissions, which is not the case, when I call the dialog directly through the ADODB PromptEdit() function.

You create a file with the connection information, which is insecure because the user does not know about it.

Regards,
Mario Muja
10/9/2005 2:12 AM | Mario Muja

Post a comment





 

 

 

Copyright © Jason Bentley