Laravel connect to a SQL Server 2008 named instance

前端 未结 2 988
抹茶落季
抹茶落季 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: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.

提交回复
热议问题