string path = AppDomain.CurrentDomain.BaseDirectory + System.DateTime.Now.ToString().Replace( " / " , "" ).Replace( @" " , "" ).Replace( " : " , "" ).Replace( " " , "" ) + " .udl " ; // 创建一个临时文件 FileStream fs = null ; fs = File.Create(path); fs.Close(); // 打开一个进程,直到我们不需要它的时候. using (Process process = new Process()) { process.StartInfo.FileName = path; process.StartInfo.UseShellExecute = true; process.Start(); while(!process.HasExited); } // 把连接字符串放到字符中. StreamReader sr = new StreamReader(path); string contents = sr.ReadToEnd(); sr.Close(); File.Delete(path); MessageBox.Show(contents);