Reputation: 245
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.
}
Upvotes: 11
Views: 1966
Reputation: 1
This problem was driving me crazy, and I finally found that when I changed from logging in as "sa" to using Windows Authentication, the problem was resolved.
Upvotes: 0
Reputation: 863
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.
Upvotes: 2