Skip to content
Advertisement

Laravel connect to a SQL Server 2008 named instance

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

this works

JavaScript

this doesn’t

JavaScript

I always end up with this error:

JavaScript

I have tried every possible combination:

  • host INSTANCE
  • host / INSTANCE
  • host \ INSTANCE

Can someone help me ?

Edit: Because I have also tried without instance name (as stated here), the script keep trying to connect until I get this error:

JavaScript

Any editor as Management studio, DBeaver or Database.NET can connect to that instance only by specifying the INSTANCENAME, so it seems more a PDO problem witht the DSN

I also have tried to connect to that named instance directly with tsql without any more luck:

JavaScript

Here the /etc/freetds.conf file:

JavaScript

And the tds log file:

JavaScript

Of course, if I try to connect to SERVER2 (which is a non named instance) everything goes smoothly…

Advertisement

Answer

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:

JavaScript

And in the laravel database adapter:

JavaScript

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

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement