2016-07-24 124 views
13

我目前正在學習SQL Server,並且在使用sqlcmd連接到本地數據庫時遇到問題。無法通過sqlcmd連接到LocalDB

當我在下面到PowerShell的類型:

sqlcmd -S "(localdb)\mssqllocaldb" 

我收到以下錯誤信息:

Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : SQL Server Network Interfaces: The system cannot find the file specified.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.

我可以連接到本地數據庫,如果我使用SQL Server Management Studio中。如果我使用實例名稱管道,我也可以連接到本地數據庫。

我有一個乾淨的安裝Windows 10 64,Visual Studio的社區,和SQL Server Management Studio中2016年

+0

是'(的LocalDB)'你的主機名和'mssqllocaldb'數據庫實例的名稱?你[啓用TCP協議](https://technet.microsoft.com/en-us/library/hh231672%28v=sql.110%29.aspx)? [參考文獻](https://msdn.microsoft.com/de-ch/library/ms188247.aspx)。 –

+0

使用'Invoke-Sqlcmd'爲我解決了這個問題。在這裏回答的建議:http://stackoverflow.com/questions/34457048/trouble-connecting-to-localdb-via-sqlcmd-in-powershell-what-is-server-instance –

+0

具有相同的問題,仍然沒有回答 –

回答

1

嘗試

sqlcmd -S ".\mssqllocaldb" 

sqlcmd -S ".\mssqllocaldb -uYOUR_User -pYOUR_PASSWORD" 
+0

並且還要確保服務已啓動 –

7

有一個driver bug ODBC驅動器13.安裝ODBC驅動程序13.1更新將解決此問題。

您可以download the driver here

之後,你應該能夠在cmd中或PowerShell來使用:

sqlcmd -S "(localdb)\MSSQLLocalDB" -i C:\path\to\file.sql