从 PHP 连接到 SQL Server 时出现“Adaptive Server 不可用或不存在”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8511369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Adaptive Server is unavailable or does not exist" error connecting to SQL Server from PHP
提问by wonder95
I'm attempting to connect to a SQL Server 2005 DB from my Mac using unixODBC and FreeTDS as I have outlined here. However, when I try to connect in to a different DB using the same setup, I get:
我正在尝试使用 unixODBC 和 FreeTDS 从我的 Mac 连接到 SQL Server 2005 DB,正如我在此处概述的那样。但是,当我尝试使用相同的设置连接到不同的数据库时,我得到:
Connection Failed:[FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist.
Here is my freetds.conf setup:
这是我的 freetds.conf 设置:
[my_db]
host = 12.34.56.789
port = 1433
tds version = 8.0
And here is my odbc.ini:
这是我的 odbc.ini:
[my_dsn]
Driver = /opt/local/lib/libtdsodbc.so
Description = My Database
Trace = no
Servername = my_db
Database = MyDB
[ODBC Data Sources]
my_dsn = FreeTDS
I am still able to connect to the other DB I set up on this computer (described in my blog post linked above), so I'm pretty sure that the error isn't on the Mac end. I've verified on the server that I'm using the correct IP address and port. Any thoughts on what could be the problem, and if it's on the server end?
我仍然能够连接到我在这台计算机上设置的另一个数据库(在我上面链接的博客文章中描述),所以我很确定错误不在 Mac 端。我已在服务器上验证我使用的是正确的 IP 地址和端口。关于可能是什么问题的任何想法,如果它在服务器端?
回答by Evgeniy Tkachenko
1. See information about the SQL server
1.查看SQL服务器信息
tsql -LH SERVER_IP_ADDRESS
locale is "C"
locale charset is "646"
ServerName TITAN
InstanceName MSSQLSERVER
IsClustered No
Version 8.00.194
tcp 1433
np \TITAN\pipe\sql\query
2. Set your freetds.conf
2.设置你的freetds.conf
tsql -C
freetds.conf directory: /usr/local/etc
[TITAN]
host = SERVER_IP_ADDRESS
port = 1433
tds version = 7.2
3 Try
3 尝试
tsql -S TITAN -U user -P password
OR
或者
'dsn' => 'dblib:host=TITAN:1433;dbname=YOURDBNAME',
See also http://www.freetds.org/userguide/confirminstall.htm(Example 3-5.)
另请参阅http://www.freetds.org/userguide/confirminstall.htm (示例 3-5。)
If you get message 20009, remember you haven't connected to the machine. It's a configuration or network issue, not a protocol failure. Verify the server is up, has the name and IP address FreeTDS is using, and is listening to the configured port.
如果您收到消息 20009,请记住您尚未连接到机器。这是配置或网络问题,而不是协议故障。验证服务器已启动,具有 FreeTDS 正在使用的名称和 IP 地址,并且正在侦听配置的端口。
回答by Jim Clouse
It sounds like you have a problem with your dsn or odbc data source.
听起来您的 dsn 或 odbc 数据源有问题。
Try bypassing the dsn first and connect using:
首先尝试绕过 dsn 并使用以下方法连接:
TDSVER=8.0 tsql -S *serverIPAddress* -U *username* -P *password*
If that works, you know its an issue with your dsn or with freetds using your dsn. Also, it is possible that your tds version is not compatible with your server. You might want to try other TDSVER settings (5.0, 7.0, 7.1).
如果可行,您就知道这是您的 dsn 或使用您的 dsn 的 freetds 的问题。此外,您的 tds 版本可能与您的服务器不兼容。您可能想尝试其他 TDSVER 设置(5.0、7.0、7.1)。
回答by Jan
After countless hours of frustration I managed to get all working:
经过无数小时的挫折,我设法让所有工作:
odbcinst.ini:
odbcinst.ini:
[FreeTDS]
Description = FreeTDS Driver v0.91
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
fileusage=1
dontdlclose=1
UsageCount=1
odbc.ini:
odbc.ini:
[test]
Driver = FreeTDS
Description = My Test Server
Trace = No
#TraceFile = /tmp/sql.log
ServerName = mssql
#Port = 1433
instance = SQLEXPRESS
Database = usedbname
TDS_Version = 4.2
FreeTDS.conf:
FreeTDS.conf:
[mssql]
host = hostnameOrIP
instance = SQLEXPRESS
#Port = 1433
tds version = 4.2
First test connection (mssqlis a section name from freetds.conf):
第一个测试连接(mssql是来自freetds.conf的部分名称):
tsql -S mssql -U username -P password
You must see some settings but no errors and only a 1>prompt. Use quitto exit.
您必须看到一些设置,但没有错误,只有1>提示。使用退出退出。
Then let's test DSN/FreeTDS (testis a section name from odbc.ini; -v means verbose):
然后让我们测试 DSN/FreeTDS(test是来自odbc.ini的部分名称;-v 表示详细):
isql -v test username password -v
You must see message Connected!
您必须看到消息已连接!
回答by Rob Forrest
I had the same issue, my problem was that the firewall on the server wasn't open from the current ip address.
我遇到了同样的问题,我的问题是服务器上的防火墙未从当前 IP 地址打开。
回答by Naidim
Responding because this answer came up first for search when I was having the same issue:
回应是因为当我遇到同样的问题时,这个答案首先出现在搜索中:
[08S01][unixODBC][FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist
[08S01][unixODBC][FreeTDS][SQL Server]无法连接:Adaptive Server 不可用或不存在
MSSQL named instances have to be configured properly without setting the port. (documentation on the freetds configsays set instance or port NOT BOTH)
MSSQL 命名实例必须在不设置端口的情况下正确配置。(有关 freetds 配置的文档说设置实例或端口不是两个)
freetds.conf
freetds.conf
[Name]
host = Server.com
instance = instance_name
#port = port is found automatically, don't define explicitly
tds version = 8.0
client charset = UTF-8
And in odbc.ini just because you can set Port, DON'T when you are using a named instance.
在 odbc.ini 中只是因为您可以设置端口,因此在使用命名实例时不要这样做。
回答by Developer
I've found an issue happen to be with the Firewall. So, make sure your IP is whitelisted and the firewall does not block your connection. You can check connectivity with:
我发现问题恰好与防火墙有关。因此,请确保您的 IP 已列入白名单,并且防火墙不会阻止您的连接。您可以通过以下方式检查连接性:
tsql -H somehost.com -p 1433
In my case, the output was:
就我而言,输出是:
Error 20009 (severity 9):
Unable to connect: Adaptive Server is unavailable or does not exist
OS error 111, "Connection refused"
There was a problem connecting to the server
回答by Geetesh
Try changing server name to "localhost"
尝试将服务器名称更改为“localhost”
pymssql.connect(server="localhost", user="myusername", password="mypwd", database="temp",port="1433")
pymssql.connect(server="localhost", user="myusername", password="mypwd", database="temp",port="1433")
回答by egmweb
Bud, disable selinux or add the following to your RedHat/CentOS Server:
Bud,禁用 selinux 或将以下内容添加到您的 RedHat/CentOS 服务器:
setsebool -P httpd_can_network_connect_db 1
setsebool -P httpd_can_network_connect 1
Best always!
永远最好!