首页 > 解决方案 > 通过批处理文件连接到 SQL Server 时出现问题?

问题描述

我有一个文件夹,我在其中生成了大约 100 个 .sql 文件,以对数据库中的各种模式进行表更改。

我正在尝试使用这篇文章中的方法来运行我的 100 个 sql 文件,但我不断收到错误消息。它适用于前几个文件,然后我开始

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Named Pipes Provider: Could not open a connection to SQL Server [53]. .
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 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..

我知道它配置为远程连接,另一个 VM 上的另一个应用程序使用它,我也检查了服务器属性。前 5-6 个 SQL 文件确实运行,但随后停止,我开始遇到此问题。关于导致它的原因以及如何减轻它的任何想法?我只是想一次做太多事情吗?

更新:我的批处理文件中的代码

for %%G in (*.sql) do sqlcmd /S ServerName /d MyDatabase -U MyUser -P "MyPassword" -i"%%G"

标签: sql-serversql-server-2016

解决方案


推荐阅读