Laravel connect to a SQL Server 2008 named instance

前端 未结 2 987
抹茶落季
抹茶落季 2021-02-09 08:23

I am trying to connect an SQL server from an Ubuntu machine, everythings works great except for named instances:

this works

\'data\' =&g         


        
相关标签:
2条回答
  • 2021-02-09 08:35

    I finally found a solution, there were two problems :

    • The SQL server wasn't listening on the good default port (my bad)
    • Laravel (PDO ?) doesn't know how to handle (or at least I haven't found how) named instances, I have tried any possible combination (see Question)

    So I finally used a combination of FreeTDS DSN with laravel in order to connect the SQL named instance server.

    The /etc/freetds.conf DSN configuration:

    [NAMED_INSTANCE]
       host = 127.0.0.1
       port = 55021
    

    And in the laravel database adapter:

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

    And that solved my problem, hope it'll help someone too

    0 讨论(0)
  • 2021-02-09 08:57

    Thanks for the participation to solve this connection problem. I also encountered this problem, here is how I solved it.

    For info in my case the connection with tsql works but not since Laravel (5.4)

    One trick I took to understand is that it is not the default port (1433) that is used.

    To find the port you must start a shell connection:

    tsql -D DB -S "IP\INSTANCE" -U login -P pass
    

    And check in the logs the good port here is 1168

    Net.c: 1059: instance port is 1168

    Contents of the file 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
    

    Contents of the file : config/database.php

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

    Now everything is working properly.

    0 讨论(0)
提交回复
热议问题