我sqlcmd.exe
来自 SQLServer 2008 和 SQLServer 2012:
PS C:\> Get-Command sqlcmd.exe
Definition
----------
C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE
C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE
通过修改$env:PATH
i 强制使用sqlcmd.exe
SQL Server 2012:
PS C:\> $env:PATH = ($env:PATH -split ";" | Where-Object { $_ -notlike "*\Microsoft SQL Server\100\*" }) -join ";"
PS C:\> Get-Command sqlcmd.exe
Definition
----------
C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE
LocalDB 的默认实例已启动并正在运行,并由当前用户拥有:
PS C:\> sqllocaldb i v11.0
Name: v11.0
Version: 11.0.2318.0
Shared name:
Owner: DOMAIN\me
Auto-create: Yes
State: Running
Last start time: 12/06/13 18:17:57
Instance pipe name: np:\\.\pipe\LOCALDB#08EDBEF0\tsql\query
(localdb)\v11.0
现在,我可以在使用时执行命令sqlcmd.exe
PS C:\> sqlcmd.exe -S "(localdb)\v11.0" -Q "select 1"
-----------
1
但是当我尝试相同的时候,Invoke-Sqlcmd
我得到一个连接错误:
PS C:\> Import-Module sqlps
PS C:\> Invoke-Sqlcmd -ServerInstance "(localdb)\v11.0" -Query "select 1"
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: 26 - Error Locating Server/Instance Specified)
我该怎么做才能Invoke-Sqlcmd
连接到lmake (localdb)\v11.0
?