我正在尝试从Ubuntu机器连接SQL服务器,除了命名实例之外,一切都很顺利:
这个可以正常工作
'data' => array(
'driver' => 'sqlsrv',
'host' => 'xxxx',
'port' => 1433,
'database' => 'db',
'username' => 'user',
'password' => 'pwd',
'prefix' => '',
),
这不是
'data' => array(
'driver' => 'sqlsrv',
'host' => 'yyyy\NAMEDINSTANCE',
'port' => 1433,
'database' => 'db',
'username' => 'user',
'password' => 'pwd',
'prefix' => '',
),
我经常遇到这个错误:
exception 'PDOException' with message 'SQLSTATE[HY000] Unknown host machine name (severity 2)' in /var/www/public/my.api/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47
我已经尝试了各种可能的组合方式:
- host \ INSTANCE
- host / INSTANCE
- host \\ INSTANCE
exception 'PDOException' with message 'SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)' in /var/www/public/my.api/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47
任何像Management Studio、DBeaver或Database.NET这样的编辑器只能通过指定INSTANCENAME连接到该实例,因此似乎更多是PDO和DSN的问题。我也尝试直接使用tsql连接到该命名实例,但没有更多的运气。
tsql -S SERVER -U usr -P pwd -L dbname
这里是/etc/freetds.conf
文件:
[global]
tds version = 8.0
client charset = UTF-8
port = 1433
dump file = /tmp/freetds.log
dump file append = yes
text size = 64512
[SERVER]
host = ip
port = 1433
instance = instance_name
[SERVER2]
host = ip
port = 1433
还有tds日志文件:
log.c:196:Starting log file for FreeTDS 0.91
on 2015-03-19 15:35:46 with debug flags 0x4fff.
iconv.c:330:tds_iconv_open(0xc163a0, UTF-8)
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1
iconv.c:187:local name for UTF-8 is UTF-8
iconv.c:187:local name for UCS-2LE is UCS-2LE
iconv.c:187:local name for UCS-2BE is UCS-2BE
iconv.c:349:setting up conversions for client charset "UTF-8"
iconv.c:351:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:391:preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion
iconv.c:394:tds_iconv_open: done
net.c:205:Connecting to 195.70.16.92 port 1433 (TDS version 7.1)
net.c:270:tds_open_socket: connect(2) returned "Operation now in progress"
net.c:306:getsockopt(2) reported: Connection timed out
net.c:316:tds_open_socket() failed
util.c:331:tdserror(0xc16140, 0xc163a0, 20009, 110)
util.c:361:tdserror: client library returned TDS_INT_CANCEL(2)
util.c:384:tdserror: returning TDS_INT_CANCEL(2)
mem.c:615:tds_free_all_results()
当然,如果我尝试连接到SERVER2(一个非命名实例),一切都会顺利进行...
NULL
,并使用'host' => 'yyyy\NAMEDINSTANCE'
。 - Guillermo Gutiérreztsql
在命名实例上给了我一个超时错误,所以我怀疑这更多是一个freeTDS的问题而不是PDO的问题。 - kitensei