Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel连接到SQL Server 2008命名实例_Php_Sql Server_Laravel_Freetds - Fatal编程技术网

Php Laravel连接到SQL Server 2008命名实例

Php Laravel连接到SQL Server 2008命名实例,php,sql-server,laravel,freetds,Php,Sql Server,Laravel,Freetds,我正在尝试从Ubuntu机器连接SQL server,除了命名实例外,其他一切都很好: 这很有效 'data' => array( 'driver' => 'sqlsrv', 'host' => 'xxxx', 'port' => 1433, 'database' => 'db', 'username' => 'user'

我正在尝试从Ubuntu机器连接SQL server,除了命名实例外,其他一切都很好:

这很有效

'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
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
我尝试了各种可能的组合:

  • 主机\实例
  • 主机/实例
  • 主机\\实例
有人能帮我吗

编辑: 因为我也尝试过不使用实例名(),所以脚本会一直尝试连接,直到出现以下错误:

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
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连接到该实例,因此DSN似乎更像是PDO问题

我还尝试使用
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()
log.c:196:启动FreeTDS 0.91的日志文件
2015-03-19 15:35:46,带有调试标志0x4fff。
iconv.c:330:tds_iconv_打开(0xc163a0,UTF-8)
iconv.c:187:ISO-8859-1的本地名称为ISO-8859-1
图标c:187:UTF-8的本地名称为UTF-8
图标编号c:187:UCS-2LE的本地名称为UCS-2LE
图标编号c:187:UCS-2BE的本地名称为UCS-2BE
iconv.c:349:为客户端字符集“UTF-8”设置转换
iconv.c:351:为“UTF-8”“UCS-2LE”转换准备iconv
iconv.c:391:为“ISO-8859-1”“UCS-2LE”转换准备iconv
iconv.c:394:tds_iconv_打开:完成
net.c:205:连接到195.70.16.92端口1433(TDS版本7.1)
net.c:270:tds\u open\u socket:connect(2)返回“操作正在进行”
net.c:306:getsockopt(2)报告:连接超时
net.c:316:tds_open_socket()失败
util.c:331:tdserror(0xc16140、0xc163a0、20009、110)
util.c:361:tdserror:客户端库返回了TDS\u INT\u CANCEL(2)
util.c:384:tdserror:returningtds\u INT\u CANCEL(2)
成员c:615:tds_free_all_results()

当然,如果我尝试连接到服务器2(这是一个未命名的实例),一切都会顺利…

我最终找到了解决方案,有两个问题:

  • SQL server未在良好的默认端口(我的坏端口)上侦听
  • Laravel(PDO?)不知道如何处理(或者至少我还没有发现如何处理)命名实例,我尝试过任何可能的组合(见问题)
因此,我最终使用FreeTDS DSN与laravel的组合来连接SQL命名的实例服务器

/etc/freetds.confDSN配置:

[NAMED_INSTANCE]
   host = 127.0.0.1
   port = 55021
在laravel数据库适配器中:

'webcmd' => array(
    'driver'   => 'sqlsrv',
    'host'     => 'NAMED_INSTANCE',
    'database' => 'db',
    'username' => 'usr',
    'password' => 'pwd',
    'prefix'   => '',
),

这就解决了我的问题,希望它也能帮助别人

谢谢大家参与解决这个连接问题。我也遇到了这个问题,下面是我如何解决的

在我的例子中,与tsql的连接是有效的,但从Laravel(5.4)开始就不起作用

我采取的一个技巧是,所使用的不是默认端口(1433

要查找端口,必须启动外壳程序连接:

tsql -D DB -S "IP\INSTANCE" -U login -P pass
并检查日志,此处的良好端口为1168

Net.c:1059:实例端口为1168

文件内容freetds.conf

[global]
    text size = 64512
    dump file = /var/log/freetds.log
    dump file append = yes

[mssql]
    host = MSSQLSRV
    port = 1168
    tds version = auto
    instance = IP\INSTANCE
    dump file = /var/log/freetds.log
    dump file append = yes
文件内容:config/database.php

 'sqlsrv' => [
            'driver'   => 'sqlsrv',
            'host'     => 'mssql',
            'port'     => '1168',
            'database' => 'DB',
            'username' => 'login',
            'password' => 'pass',
            'prefix'   => '',
        ],

现在一切正常。

尝试将端口号设置为
NULL
,并使用
'host'=>'yyyy\NAMEDINSTANCE'
相同的错误,我用更多的测试更新了我的问题,
tsql
给我一个命名实例超时,所以我怀疑这更像是freeTDS的问题,而不是PDO的问题problem@GuillermoGuti埃雷兹的工作就像一个魔咒……几年后。非常感谢。这是拯救我的一天。谢谢!!在使用ppa:ondrej/php的ubuntu 16.04上,我必须首先运行这个:sudo apt get install php7.0-sybase freetds common libsybdb5