Invoke-Sqlcmd:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误 [英] Invoke-Sqlcmd : A network-related or instance-specific error occurred while establishing a connection to SQL Server

查看:157
本文介绍了Invoke-Sqlcmd:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 PowerShell 使用 .sql 文件创建一个表.

I want to create a table using .sql file through PowerShell.

以管理员身份在 Windows PowerShell ISE 中运行以下内容:

Running following in Windows PowerShell ISE as Administrator:

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

但是这给出了以下错误:

But this is giving following error:

Invoke-Sqlcmd:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误.这服务器未找到或无法访问.验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接.(提供程序:SQL 网络接口,错误:25 - 连接字符串无效)

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)

任何人都可以指导解决这个问题.

Could any one please guide to fix this.

我已经参考了使用powershell执行.sql

推荐答案

在我手动尝试连接 SQL Server Management Studio 后,我自己得到了答案.

I myself got the answer after I manually tried to connect the SQL Server Management Studio.

那里将服务器名称作为本地主机.实例名不用说了,就是连接到默认实例.

There it's taking server name as localhost. No need to mention the instance name, it's connecting to default instance.

这有效:

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

这篇关于Invoke-Sqlcmd:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆