2015-02-12 25 views
1

我使用此代碼通過c#打開文件夾中的ssms。自動執行通過c#打開的SSMS .exe

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

    } 

現在我想自動執行已打開,使得用戶劑量沒有必須按「執行」按鈕或F5 SSMS。

謝謝。

+1

很明顯,我沒有關於您正在處理的特定場景或您希望用戶如何處理輸出的上下文,但是您是否考慮過僅使用SQLCMD並可選擇將輸出發送到文件? – 2015-02-12 03:55:37

+0

是的,如果你用SQLCMD.EXE替換了ssms.exe,它可能會做你想做的! – 2015-03-05 14:09:02

回答

2

運行SSMS /?從命令行看來,沒有辦法做你想做的事。你需要使用sqlcmd,因爲他們已經在上面發佈了。

用法: ssms.exe [-S server_name [\ instance_name]] [-d數據庫] [-U用戶] [-P密碼] [-E] [文件名[,文件名]] [/?]

[-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 
+0

另請參閱:http://stackoverflow.com/questions/10261855/how-to-run-sql-script-using-sql-server-management-studio – Derek 2015-03-05 12:50:07