PHP: Connect to a MS SQL Server with Dynamic Port Allocation

Solution:
Given that your answer was correct, I had to do minor changes to make it work. I decided to write them here. Steps are basically the same. On Ubuntu/Debian:
apt-get install php5-sybase unixodbc tdsodbc
Edit/etc/odbcinst.ini
and add driver details
[TDS]
Description = FreeTDS Driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
Edit/etc/odbc.ini
and enter connection details
[SQLSRV01]
Description = SQL Server test
Driver = TDS
Trace = No
Server = SERVER_IP\INSTANCE_NAME
TDS_Version = 9.0
#Database = DataBaseName
#ReadOnly = Yes
The last two parameters are optional. Driver must match what we wrote in odbcinst.ini. The Server directive must be in that syntax (of course SERVER_IP can be an hostname too).
According to UnixODBC the next step should not be necessary, but this is what made my installation work. Run the following command (every time odbc.ini is changed)
odbcinst -i -s -f /etc/odbc.ini
After this you should be able to connect using:
isql -v SQLSRV01 nome_utente password
Or via PHP:
$db = new PDO("dblib:host=SQLSRV01;dbname=DBNAME","USERNAME","PASSWORD");
Answer
Solution:
Short answer:
ODBC drivers know to contact SQL server on port 1434 to find which dynamic port is associated with a named instance. userSERVERNAME\INSTANCENAME
to connect.
Long answer:
I started here which led here and here.
Eventually I found this:
If you are using mssql with multiple instances and dynamic port allocation you can use the following:
[SQLServer2008] Description = Production Server Driver = TDS Trace = No Server = servername\instance_name TDS_Version = 8.0
Which seems to be echoed in a similar IBM Doc:
Question
SQLServer is setup to dynamically assign ports. In the .odbc.ini file, the Address parameter is usually set to hostname colon port number (Address=HostName:1433), but the port may change. How should we handle this?
Answer
For the Address parameter value, instead of entering the hostname colon port, enter the hostname a backslash and the server instance name.
For example, in Unix/Linux, use the IBM SQLServer Wire Protocol driver and enter the following in the .odbc.ini file in the DSN definition for the connection to the SQLServer data source:
Address=HostName\Server_Instance_Name
For Windows, use the ODBC Data Sources Administrator to configure a System DSN for the data source using the IBM SQLServer Wire Protocol driver.
Note: The parameter is Server
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: method illuminate\database\eloquent\collection::paginate does not exist.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.