Rangesh
Rangesh

Reputation: 728

Bind to Existing Process

I am trying to open SQL Server Management studio,programitically, i have used Process to open SQL Server and have used Start() Method to open the process,

                    using System.Diagnostics;
                    Process Sql = new Process();
                    string strfile1="example1.sql";
                    string strfile2="example2.sql";
                    Sql.StartInfo.FileName = "Ssms.exe";//sql server process
                    Sql.StartInfo.Arguments = strfile1;
                    Sql.Start();
                    Sql.StartInfo.Arguments = strfile2;
                    Sql.Start();

This code opens two instance of SQL server,but I want to check if the process is already running and reuse the existing process and open the example2.sql in the same Process.How can this be done ?

Upvotes: 2

Views: 1050

Answers (2)

CodeCaster
CodeCaster

Reputation: 151604

What if you let the OS decide what to do?

Process.Start("example1.sql");
Process.Start("example2.sql");

Upvotes: 1

Dutts
Dutts

Reputation: 6191

You can check if a process is running by name (you need to find out the name of your ssms process) like this:

Process[] procName= Process.GetProcessesByName("INSERT NAME HERE");
if (procName.Length >= 0)
{
  //you are already running
}

but I don't think you'll be able to then modify an existing instance of ssms.

Upvotes: 1

Related Questions