2015-06-20 111 views
3

我想通過PowerShell使用.sql文件創建表。Invoke-Sqlcmd:建立與SQL Server的連接時發生網絡相關或實例特定的錯誤

運行在Windows PowerShell ISE以下爲管理員:

Invoke-Sqlcmd -InputFile 'D:\SQL Scripts\test.sql' -ServerInstance 'localhost\MSSQLSERVER' -Database 'Test' 

但是,這是給下面的錯誤:

Invoke-Sqlcmd : A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)

可以在任何一個請指導,以解決這個問題。

我已經審閱execute .sql using powershell

回答

3

我自己得到的答覆後,我手動嘗試連接SQL Server Management Studio中。

它有服務器名稱作爲本地主機。不需要提及實例名稱,它將連接到默認實例。

這工作:

Invoke-Sqlcmd -InputFile 'D:\SQL Scripts\test.sql' -ServerInstance 'localhost' -Database 'Test' 
相關問題