I have a C# application that, when a user clicks a button, will open SQL Server Management Studio query editor with a specified server and database connection. What I would like to do is be able to have this same functionality, but with an already running instance of SSMS (not start a new process).
My code so far:
if (IsProcessOpen("Ssms") == false)
{
Process ssms = new Process();
ssms.StartInfo.FileName = "C:\\Program Files (x86)\\Microsoft SQL Server\\110\\Tools\\Binn\\ManagementStudio\\Ssms.exe";
ssms.StartInfo.Arguments = "-S " + StaticVariables.Getserver + " -d " + StaticVariables.Getdatabase;
ssms.Start();
}
else
{
//In already running SSMS process, open connection to server and database with new query window.
}
As far my research goes, there is no API available to interact with an existing SSMS processs. (http://stackoverflow.com/questions/2334435/how-do-i-programmatically-open-a-new-tab-in-an-open-instance-of-sql-management-s)
You could try doing a hack involving SendKeys, but this would have a downside of not knowing the current state of the SSMS window (if it has any active windows open or anything)
If you could share the original requirement, we may look at some better alternatives.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With