我有一个使用osql连接到SQL Server 2005命名实例的脚本。但该脚本会引发以下错误:
[SQL Native Client]Named Pipes Provider: Could not open a connection to SQL Server [53].
[SQL Native Client]Login timeout expired
[SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.
脚本的连接部分如下所示:
osql -E -S <servername>\<named_instance> -i D:\scripts\script1.sql -o D:\scripts\script1.txt
我的问题是:导致此错误的原因是什么,可能的解决方案是什么?
答案 0 :(得分:1)
-S参数指定实例。您的示例显示'\'。您需要将其更改为:
osql -E -S localhost\myInstance -i D:\scripts\script1.sql -o D:\scripts\script1.txt
http://msdn.microsoft.com/en-us/library/aa214012(SQL.80).aspx
您可能还需要验证您的客户端和服务器配置是否同意传输(共享内存,命名管道,TCP / IP)等...
答案 1 :(得分:0)
确保您的SQL Server允许远程连接,并且您已启用TCP / IP和命名管道连接。