自动执行通过c#打开的SSMS .exe

Auto Execute SSMS .exe opened through c#

我使用此代码通过 C# 从文件夹中打开 ssms。

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 ");

    }

现在我想自动执行已打开的 ssms,这样用户就不必按 "execute" 按钮或 F5

谢谢。

正如GB所说,您似乎想要的是使用SQLCMD。请参阅下面的 link:

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

运行 ssms /?在命令行中,似乎没有选项可以执行您想要的操作。您需要使用上面发布的 sqlcmd。

用法: ssms.exe [-S server_name[\instance_name]] [-d 数据库] [-U 用户] [-P 密码] [-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