When I run apache (via xampp) as a standalone server not as a service (on Windows Server 2008)
with the following connection code everything works fine (username and password removed )
$server = "WMS";
$link = odbc_connect($server,'','');
if (!$link) {
die('Something went horribly wrong while connecting to MSSQL');
}else {echo('');}
If however I change apache to run as a service in Windows the connection breaks and I get the following error message
Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in
C:\xampp\htdocs\Dev\well.php on line 30
Something went wrong while connecting to MSSQL
Please read documentation: http://uk.php.net/manual/en/function.odbc-connect.php
$server = "WMS";suggests that you have ODBC alias/data source configured with that name. Error message clearly says that data source with such name (WMS) is not found. On Windows 7/Vista/XP/Server you can configure them at “Start -> Administrative Tools -> Data Sources (ODBC)” — path can be different on older OS. In any case — look for “Microsoft ODBC Data Source Administrator”.Instead of using alias, I would recommend (the way I always connect) to use full DSN name, e.g.
In this case everything is part of the script and no external dependencies.
BTW — instead of using ODBC Functions, I would recommend using PDO & driver specially for MS SQL Server: PDO_SQLSRV — http://uk.php.net/manual/en/ref.pdo-sqlsrv.php (or Microsoft SQL Server Driver for PHP if you prefer old procedural style — http://uk.php.net/manual/en/book.sqlsrv.php )