doumao1519 2014-04-23 15:52
浏览 39

MSSQL VIA FreeTDS,ODBC和Cpanel未知主机名(严重级2)

I have installed FreeTDS 0.91, ODBC, on a Cpanel server running Centos 6.5x64. Everything appears to be running fine and I can connect to the remote MSSQL 2012 server using:

/usr/local/freetds/bin/tsql -S sqlserver -U test -P mypassword

and succesfully execute queries in the database.

I can also connect through:

isql -v sqlserverdatasource test mypasswordhere

But for some reason /usr/local/freetds/bin/tsql -LH server.ip.here

returns no information or errors which doesn't make much sense when it is proven I can connect with the other methods above.

So now when running a test script from a cpanel account on the machine I get:

Unknown host machine name (severity 2)

Here is the test script:

//Database connection function.
function getConnection() {
    try {

    //$dbconnect = new PDO("sqlserver:Server=server.ip.here,1433;Database=dbname", "user", "password");
    $dbconnect = new PDO("dblib:host=server.ip.here,1433;dbname=dbname", 'user', 'password'); 
    } catch (PDOException $e) {
        echo "CONNECTION ERROR.<br>Error message:<br><br>" . $e->getMessage();
        die();
    }
    if (!$dbconnect) {
        die('Cant connect to database. Please try again later!');
    }
    else{
        echo "i'm in!";
        return $dbconnect;
    }
}

The first commented line is the old one using sqlserv which I found did not work at all from what i can tell because of the x64 OS. I have also tried with "" around user and pass as well as no marks at all.

php -m does show PDO and pdo-dblib.

Any ideas where I can look next?

Update: This was fixed. I missed in freetds.conf:

[global]
    # TDS protocol version
    tds version = 8.0

It was originally set to 4.5 instead of 8.

  • 写回答

2条回答 默认 最新

  • dsxgby126001 2015-02-20 07:49
    关注

    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.

    评论

报告相同问题?