[unixODBC-support] Error in PHP mode: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source, SQL state

Gérard Maulino gerard at dkeystone.com
Mon Jun 15 12:40:15 BST 2009


Hi Abel,

I just fixed this but I'm not sure what did the fix. I did 2 changes since I
had the error:

- Re installed Freetds from the CVS source tree.
- Removed some environment variable declarations (found somewhere on the
net..) in the PHP file.  
    putenv("FREETDSCONF=/usr/local/etc/freetds.conf");
    putenv("ODBCSYSINI=/usr/local/etc/odbcinst.ini");
    putenv("ODBCINI=/usr/local/etc/odbc.ini");

In my opinion the latest is the good one because I found it by looking at
the PHP strace result and saw interesting lines:

(traces contained in the traces.log file created by '# strace  2>traces.log
php /path_to_php_file/php_file.php')
    ...
    open("/usr/local/etc/odbcinst.ini/odbcinst.ini", O_RDONLY) = -1 ENOENT
(No such file or directory)
    open("/usr/local/etc/odbcinst.ini/odbcinst.ini",
O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory)
    access("/usr/local/etc/odbcinst.ini/odbc.ini", F_OK) = -1 ENOENT (No
such file or directory)
    open("/usr/local/etc/odbcinst.ini/odbcinst.ini", O_RDONLY) = -1 ENOENT
(No such file or directory)
    open("/usr/local/etc/odbcinst.ini/odbcinst.ini",
O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory)
    ...
Apparently the ODBCSYSINI variable is pointing to a directory. So removing
the filename should be enought but I found that it worked without the
variable.

Anyway the use of strace was a suggestion from Nick on this mailing list and
it's really helpful so thanks for that! Also I was surprised to see that
remote database access are pretty fast despite the use of
ApachePHP/unixODBC/FreeTDS/SQLServer combination. 

Hope that helps.

Regards,

Gerard

-----Original Message-----
From: abel.garciac at gmail.com [mailto:abel.garciac at gmail.com] 
Sent: vendredi 12 juin 2009 20:48
To: gerard at dkeystone.com
Subject: Error in PHP mode: [unixODBC][FreeTDS][SQL Server]Unable to connect
to data source, SQL state

Gerard, you were able to fix this?. I have the same error. 

Thanks, Abel.

***********************************************
Thanks for your reply Nick, 

So by looking for Freetds issues on google I found something which suggested
to add the environment variables in the PHP script. So I added the following
lines at the top of the page: 

  putenv("FREETDSCONF=/usr/local/etc/freetds.conf");
  putenv("ODBCSYSINI=/usr/local/etc/odbcinst.ini");
  putenv("ODBCINI=/usr/local/etc/odbc.ini"); 

And now the connection (odbc_connect()) is still failing but the httpd error
is a little different: 

PHP Warning:  odbc_connect() [<a
href='function.odbc-connect'>function.odbc-connect</a>]: SQL error: 
[unixODBC][Driver Manager]Data source name not found, and no default driver
specified, SQL state IM002 in SQLConnect in
/usr/local/SalomeTMF/DK/DK_Fogbugz.php on line 17 

If I 'su apache' and run isql in command line that works. 
Any idea? 

Thanks, 

Gerard 




More information about the unixODBC-support mailing list