So I've written a simple exe that will extract sql files from a zipped folder and open them in SQL Server Studio. It works great except that sometimes there will be multiple sql files to open, which then causes multiple SQL Server Instances to open. How can I make the files all open in one instance?
This is what I'm trying so far:
foreach (string sqlFile in files) { Process sqlServer; if (Process.GetProcessesByName("Ssms").Length > 0) sqlServer = Process.GetProcessesByName("Ssms")[0]; else sqlServer = new Process(); sqlServer.StartInfo.FileName = sqlFile; sqlServer.Start(); } Sometimes a file will magically open in an existing SQL Server window but I haven't figured out why.