1

I use this code to open ssms from a folder through c#.

private void button1_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process.Start("ssms.exe", @"-S server-name -d db_name -E F:\\sql_files\Batch1.sql ");

    }

Now i want to Auto execute ssms that has opened so that user dose not have have to press "execute" button or F5.

Thank you.

Faisal
  • 61
  • 1
  • 12
  • 1
    Obviously I have no context for the specific scenario you are dealing with or what you expect your user to do with the output, but have you considered just using SQLCMD and optionally sending the output to a file? – G B Feb 12 '15 at 03:55
  • Yes if you replaced ssms.exe with SQLCMD.EXE, it would probably do what you wanted! – Nick.Mc Mar 05 '15 at 14:09

2 Answers2

2

Running ssms /? from the command line, it appears there is no option to do what you want. You need to use sqlcmd as they have posted above.

Usage: ssms.exe [-S server_name[\instance_name]] [-d database] [-U user] [-P password] [-E] [file_name[, file_name]] [/?]

[-S The name of the SQL Server instance to which to connect]
[-d The name of the SQL Server database to which to connect]
[-E]    Use Windows Authentication to login to SQL Server
[-U The name of the SQL Server login with which to connect]
[-P The password associated with the login]
[file_name[, file_name]] names of files to load
[-nosplash] Supress splash screen
[/?]    Displays this usage information
Derek
  • 7,615
  • 5
  • 33
  • 58
  • see also: http://stackoverflow.com/questions/10261855/how-to-run-sql-script-using-sql-server-management-studio – Derek Mar 05 '15 at 12:50
1

As GB said, what you seem to want is to use SQLCMD. See the link below:

https://msdn.microsoft.com/en-us/library/ms170572.aspx

Juan
  • 3,675
  • 20
  • 34