Ubuntu – SQLSTATE[HY000] Unknown host machine name (severity 2)

networkingserversql

I have a problem in which I can not find a solution and I was hoping that you could help me out.
I rolled back my server and now none of the php scripts can now connect to other servers. The scripts are up to date as the rollback is from last week.

I get the SQL error:

SQLSTATE[HY000] Unknown host machine name (severity 2)

And on cmd I get:

SQLState = S1T00, NativeError = 0 Error = [unixODBC][Microsoft][SQL
Server Native Client 11.0]Login timeout expire
d SQLState = 08001, NativeError = 10022 Error =
[unixODBC][Microsoft][SQL Server Native Client 11.0]A network-related
or instance-specific
error has occurred while establishing a connection to SQL Ser
ver. Server is not found or not accessible. Check if instance name is
correct an d if SQL Server
is configured to allow remote connections. For more information
see SQL Server Books Online. SQLState = 08001, NativeError = 10022
Error = [unixODBC][Microsoft][SQL Server Native Client 11.0]TCP
Provider: Error code
0x2726

On telnet I can connect to remote server.
sqlcmd also lets me connect to the remote server

Please if anyone could help me out. I do not know what to do next.
All help will be greatly appreciated.

This is a test script to try the connection

$link = mssql_connect('xx.xxx.xxxx.xx,1433','myuname','mypwd');

    if (!$link) {
    die('Something went wrong while connecting to MSSQL:'. mssql_get_last_message());
    }

Best Answer

The fix for me was with three steps:

First, I edited /etc/freetds/freetds.conf and changed the tds version like this:

tds version = 8.0

The second step was not entering port number. The port was already 1433, and not specifying it fixed the exact same issue on my case.

Lastly, to connect properly, I had to restart networking as @user1054844 mentioned as this:

/etc/init.d/networking restart

After all these steps, I was able to connect and work with the SQL Server database.

Related Question