SQL Server DNS

Was having problems getting my PDO to connect to the SQL Server with ODBC.
And to make matters worse I am on a windows LAN, the web server is a *nix box and my testing computer is M$. My DSN just was not right and wouldn't play - my host string was off and any permutation I used wasn't working. Looked at the PDO docs, the DSN docs in the manual, connectionstrings.com and no love.

I am most comfortable working with MySQL so getting the SQL Server to play had been frustrating in the extreme (hate when simple things are made hard - wanted to kick something). Turned out I needed to add my "instance" of the SQL server (not my word - bosses) to the host. So what did I finally come up with that works

PHP:
  1. $host = '192.0.0.0\InstanceName';
  2. $user = 'user';
  3. $pass = 'xxxxxxxx';
  4. $db = 'test';
  5.  
  6. $dbh = new PDO("odbc:Driver={SQL Server};Server=$host;Database=$db;Uid=$user;Pwd=$pass;");

* was it just me or was that an alphabet soup?

del.icio.us:SQL Server DNS  digg:SQL Server DNS  furl:SQL Server DNS  reddit:SQL Server DNS

3 Responses to SQL Server DNS

  1. kenrick :

    if you have freetds compiled in youll have to add the sql server host to your freetds.conf file for it to work. At least thats what I have to do to get any connections, be it odbc or mssql to work.

  2. Wez Furlong :

    Not really 100% related, but I’d thought I’d take the opportunity to help an anticipated FAQ… if your web server is on windows then you’ll have a MUCH better time if you set your Driver to SQL Native Client instead of SQL Server. The SQL Native Client driver is far superior to the older SQL Server drivers.

  3. PHPDeveloper.org :

    Ligaya Turmelle’s Blog:…

Leave a Reply