【发布时间】:2013-06-05 18:28:37
【问题描述】:
我有一个 "SQL" 脚本,需要通过 Windows Powershell 运行才能创建数据库。该脚本已经具有 drop 和 create 功能,因此无需在命令行末尾添加数据库名称。尝试执行命令行时,我收到一条错误消息,提示
"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)
At line:1 char:14
+ invoke-sqlcmd <<<< -inputfile "c:\A.sql" -serverinstance "Louis_dev\MSSQLSERVER"
+ CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], SqlException
+ FullyQualifiedErrorId : SqlExectionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
Invoke-Sqlcmd :
At line:1 char:14
+ invoke-sqlcmd <<<< -inputfile "c:\A.sql" -serverinstance "Louis_dev\MSSQLSERVER"
+ CategoryInfo : ParserError: (:) [Invoke-Sqlcmd], ParserException
+ FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand"
不确定它是否是调用命令,我已经按照此链接How to execute .sql file using powershell? 中的步骤进行操作。是否有任何机会可以解决此错误。 SQLSERVER 实例已配置为 LocalSystem 而不是网络实例
【问题讨论】:
-
您的 sql 实例启用了 tcp/ip 和命名管道协议?
-
我在哪里可以检查这个?
-
据此,我的 SQLServer 实例安装为 LocalSystem。我必须将其更改为网络服务吗?
-
您能否成功使用其他工具,例如 SSMS、sqlcmd.exe 甚至设置测试 DSN?
标签: powershell sql-server-2008-r2