I am using Ubuntu 14.04 and i have installed freetds and odbc taking guidance from this link : http://www.bictor.com/2014/05/13/configure-unixodbc-for-ubuntu-14-04-using-freetds/
The database i am trying to connect to is on another system (mssql 2008 r2 express server) .
When i try to connect to that system database using the : isql -v test command .
When i do that i get the below errors :
> [S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
> [01000][unixODBC][FreeTDS][SQL Server]Unknown host machine name.
> [ISQL]ERROR: Could not SQLConnect
My odbc.ini file looks like this :
[test]
Driver = FreeTDS
Description = My Test Server
Trace = No
ServerName = HOME-PC\ZOLIPE
Port = 1433
Database = test
TDS_Version = 4.2 (This version is the same as reported by tsql -C command)
i have also added the below in my freetds.conf file :
[mssql]
host = HOME-PC\ZOLIPE
Port = 1433
tds version = 4.2
Please help and thanks in advance .
Related
I am trying to run a zend + doctrine web application from a Debian 9 host, using php 5.6
I've the need to connect to a sql server that is on different host (it's a windows machine, obviously)
I tested connection using isql command line and I am correctly able to login and to operate in the desired db
The problem is that the webabb do not return me any error but simply fails to login (i am not the developer of this webapp).
Configuration follows:
odbcinst.ini
[FreeTds]
Description = MS SQL database access with Free TDS
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
UsageCount = 1
Trace = Yes
TraceFile = /tmp/odbcinst.log
freetds.ini
host ip is exact, I removed when pasting here
[flower1]
host = xxx.xxx.xxx.xxx
port = 1433
tds version = 7.3
odbc.ini
[test_flower1]
Description=Test for MSSQL Server on flower1
Driver=FreeTds
Database=test_flower1
ServerName=flower1
TDS_Version=7.3
application.ini
;; Database
doctrine.dsn = "odbc:Driver={Sql_server};Server=flower1;Database=test_flower1;Uid=<redacted but correct>;Pwd=<redacted but correct>;"
How can I debug the source of the problem?
I've not previously experience with zend/doctrine
The problem was due to this
doctrine.dsn = "odbc:Driver={Sql_server};Server=flower1;Database=test_flower1;Uid=<redacted but correct>;Pwd=<redacted but correct>;"
I solved simply adding the port !
doctrine.dsn = "odbc:Driver={Sql_server};Server=flower1;Port=1433;Database=test_flower1;Uid=<redacted but correct>;Pwd=<redacted but correct>;"
I have tried to connect sybase from terminal using FreeTDS and it is working fine but I am not able to connect database using PHP.
I have done changes in below files.
/etc/odbc.ini file:
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
Server =
Port =
Database =
Username =
Password =
freetds.conf file
[sybase]
host=
port=
Tds version=5.0
It is working fine using Terminal
tsql -S SYBASE -U username -P password
But from PHP connection I am getting error:
[unixODBC][Driver Manager]Data source name not found, and no default driver specified
PHP file code:
$db = ADONewConnection('odbc');
$DSN ='UID=username;PWD=password;EngineName=dbServiceName;AutoStop=No;Integrated=No;Debug=No;DisableMultiRowFetch=No;CommLinks=SharedMemory,TCPIP{};Compress=No;Driver={FreeTDS}';
$db->Connect($DSN );
I know in some versions, you need to use the IP of the server rather than the name, like this in freetds.conf:
[myserver]
host = 10.10.10.10
port = 5000
tds version = 5.0
I also don't know if tds version is case sensitive, but I've always seen it in lowercase. Are you sure that PHP is reading from the same freetds.conf that the command line version is?
I'm developing a web application with an AWS EC2 server (using php) to access a MS SQL Server database.
After a long search for solutions, I found this solution to use an ODBC driver. Fine, the development went well and I have no problems to connect to database or persist data.
But when I deployed my application, any action returns this error:
ERRO: IM001: [unixODBC][Driver Manager]Driver does not support this
function
I really tried all that I know and couldn't resolve this.
My EC2 configuration is:
yum install unixODBC unixODBC-devel freetds freetds-devel
And my odbc/freetds conf files are:
/etc/odbc.ini
[TDS_NAME]
Description = decription
Driver = TDS_NAME
Database = MY_DB
Servername = TDS_NAME
UID = VIPS
Port = 1433
TDS_Version= 7.3
/etc/odbcinst.ini
[TDS_NAME]
Description = TDS Connection
Driver64 = /usr/lib64/libtdsodbc.so
Setup64 = /usr/lib64/libtdsS.so
FileUsage = 1
UsageCount = 1
[ODBC]
Trace = yes
TraceFile /tmp/odbc.log
/etc/freetds.conf
[TDS_NAME]
host = MY_HOST
port = MY_PORT
tds version = 7.3
I run my queries using odbc_execute() or odbc_exec() and the error happens when my consult has some parameter. I'm pretty sure that the problem isn't my configuration files because I can connect successfully to the server and run a simple "SELECT * FROM table" and connect using isql running any query goes well.
Anyone can help me?
OBS: PHP RUNNING VERSION - PHP 5.6.10
A few things to consider:
What version of FreeTDS are you running?
What version of SQL Server are you running?
You need this to properly pick the correct TDS version. You're configured to use TDS 7.3, which would require FreeTDS 0.95 and SQL Server 2008. If you're just doing basic stuff, perhaps consider changing your TDS Version to 7.2 or 7.1?
Here's a handy chart of what features are supported by which TDS version in FreeTDS:
http://www.freetds.org/userguide/choosingtdsprotocol.htm
Good luck!
I have an Ubuntu 12.04 server and I'm trying to establish a connection to a MSSQL database.
I've managed to connect using tsql and isql, but osql doesn't work and connecting with PHP using PDO also isn't working.. I will try to provide as much information as I can and if you need more just let me know and I will edit.
freetds.conf:
[MSSQL]
host = TPSACC
port = 54488
tds version = 8.0
odbc.ini:
[MSSQL]
Description = MS SQL connection to PRODUCTION database
Driver = FreeTDS
Database = PRODUCTION
Server = TPSACC
UserName = sa
Password = pass
Trace = No
TDS_Version = 8.0
Port = 54488
odbcinst.ini:
[FreeTDS]
Description = ODBC for Microsoft SQL
Driver = /usr/local/lib/libtdsodbc.so
UsageCount = 1
Threading = 2
~> isql MSSQL sa pass
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
~> tsql -S MSSQL -U 'sa' -P 'pass'
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>
~> osql -S MSSQL -U sa -P pass
checking shared odbc libraries linked to isql for default directories...
strings: '': No such file
trying /tmp/sql ... no
trying /tmp/sql ... no
trying /etc ... OK
checking odbc.ini files
reading /home/toolplas/.odbc.ini
[MSSQL] not found in /home/toolplas/.odbc.ini
reading /etc/odbc.ini
[MSSQL] found in /etc/odbc.ini
found this section:
[MSSQL]
Description = MS SQL connection to PRODUCTION database
Driver = FreeTDS
Database = PRODUCTION
Server = TPSACC
UserName = sa
Password = pass
Trace = No
TDS_Version = 8.0
Port = 54488
looking for driver for DSN [MSSQL] in /etc/odbc.ini
found driver line: " Driver = FreeTDS"
driver "FreeTDS" found for [MSSQL] in odbc.ini
found driver named "FreeTDS"
"FreeTDS" is not an executable file
looking for entry named [FreeTDS] in /etc/odbcinst.ini
found driver line: " Driver = /usr/local/lib/libtdsodbc.so"
found driver /usr/local/lib/libtdsodbc.so for [FreeTDS] in odbcinst.ini
/usr/local/lib/libtdsodbc.so is an executable file
"Server" found, not using freetds.conf
Server is "TPSACC"
osql: no IP address found for "TPSACC"
In PHP I have:
$conn = new PDO ("dblib:host=TPSACC;dbname=PRODUCTION","$username","$pw");
..or..
$conn = new PDO ("dblib:host=TPSACC;port=54488;dbname=PRODUCTION","$username","$pw");
And they both return this error:
SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)
I have been stuck here for a couple days and can't quite figure out why only half of the connections actually work..
Any and all help is really appreciated, thanks!
EDIT: It is different than that question, I explained in a comment but will repost here:
For that one the problem was that the port was changed from 1433. Mine was also changed and I fixed that, the port is now 54488 and since that change tsql and isql have been working. However, it still doesn't solve the osql and PHP issues.
osql is choking on something in your configuration. osql is a debugging utility which simply checks out your configuration, then passes along to unixODBC's isql to connect (http://linux.die.net/man/1/osql). Try this for your odbc.ini:
[MSSQL]
Driver = FreeTDS
Description = MS SQL connection to PRODUCTION database
Server = tpsacc.yourfulldomain.com
Port = 54488
TDS_Version = 7.2
Database = PRODUCTION
UserName = sa
Password = pass
Trace = No
Also, are you sure that's the correct location for libtdsodbc.so? When I install freetds-dev with Ubuntu 14 x64 (utopic), it installs to /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so; example odbcinst.ini:
[FreeTDS]
Description = v0.91 with protocol v7.2
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
And for good measure, the typical freetds.conf I use:
# A typical Microsoft server
[MSSQL]
host = tpsacc.yourfulldomain.com
port = 54488
tds version = 7.2
FreeTDS only supports up to TDS version 7.2 with most languages. While using "8.0" shouldn't break anything, using 7.2 is better for consistency. If you need to check for reference, I have a Vagrant box with a full configuration available here, with examples: https://github.com/FlipperPA/django-python3-vagrant/ Good luck!
If you search Google for this question, you will find a lot of incorrect, misleading, and outdated information. Surprisingly, there isn't a solid answer on Stack Overflow, so we should change that.
I am using the Mac port installation of Apache and PHP. I have installed php5-mssql, and I can see mssql on my phpinfo() page.
But I don't see it listed under PDO.
PDO support enabled
PDO drivers dblib, mysql, odbc, pgsql
Is mssql not associated with PDO? Is there another driver that can be used on a Mac to connect to a SqlServer database using PDO? Seems like this is something that should be possible.
Does this help you?
http://blog.nguyenvq.com/2010/05/16/freetds-unixodbc-rodbc-r/
I use FreeTDS to connect to Microsoft SQL servers from a Linux server and it looks like the person in the link above has used FreeTDS to connect from a Mac.
Here is my /etc/freetds/freetds.conf file (the only part I added was at the very end for the XYZ server):
[global]
# TDS protocol version
; tds version = 4.2
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
; dump file = /tmp/freetds.log
; debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
# Define a connection to the MSSQL server.
[xyz]
host = xyz
port = 1433
tds version = 8.0
[Edit by the asker]
FreeTDS configuration is the first half of the answer. Once it's configured you should be able to run something like this from the command line and connect:
tsql -S xyz -U username -P password
Then you need to use dblib, not mssql, as the PDO driver:
$pdo = new PDO("dblib:host=$dbhost;dbname=$dbname",
"$dbuser","$dbpwd");
Where $dbhost is the name from the freetds.conf file
After looking at many threads, I've found that the best way to connect to MSSQL from Mac OS X with PHP 7 or older is to use dblib. (Just download the correct php version)
You can follow these instructions (ignoring the mssql.so extension) to connect very easily:
https://github.com/BellevueCollege/public-docs/blob/master/PHP/configure-mssql-pdodblib-mac.md
It worked perfect with OS X El Capitan, Bitnami with PHP 7.
Steps
1.- Install XCode
$ xcode-select ---install
2.- Install Homebrew
3.- Install autoconf using Homebrew.
$ brew install autoconf
4.- Install FreeTDS
$ brew install freetds
5.- Download your version of PHP Source and uncompress it.
6.- Build the PDO DBLIB extension (Example for PHP 5.5.14)
$ cd php-5.5.14/ext/pdo_dblib
$ phpize
$ ./configure --with-php-config=/usr/bin/php-config --with-pdo-dblib=/usr/local/
$ make
$ sudo cp modules/pdo_dblib.so /usr/lib/php/extensions/no-debug-non-zts-20121212
7.- Add the .so extensio to php.ini
extension=pdo_dblib.so
8.- Restart Apache
9.- Connect using the dblib dsn:
$pdo = new PDO("dblib:host=$dbhost;dbname=$dbname","$dbuser","$dbpwd");
dblib is the driver that need to be used with mssql on unix systems
No need for you to install anything else,
<?php
$dsn = 'dblib:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';
$dbh = new PDO($dsn, $user, $password);
Thanks Esteban for the nice guide (https://stackoverflow.com/a/37707426) which succesfully helped me install the pdo_dblib driver.
However, I was having issues connecting to my Azure SQL database from OSX 10 with PHP (5.5) and FreeTDS using the provided dblib dsn. What finally fixed it for me was appending the Azure database (m53man42a) to my username.
My dblib PDO connection in PHP:
$conn = new PDO("dblib:host=azure-sql;dbname=my-database-name",
"username#m53man42a",
"my-secret-password");
My FreeTDS.conf:
[azure-sql]
host = m53man42a.database.windows.net
port = 1433
tds version = 8.0
client charset = UTF-8
text size = 20971520
Consider adding this as a bullet number 10 in your list... :D
Note that Microsoft have published a PHP7 extension for this, but if you're still on PHP5.x, that doesn't help you. I've succeeded in connecting using a different stack: freetds,odbc,pdo.
I'm using OS X 10.11.6 (El Capitan) with Macports, PHP5.6.
I've started by creating an Azure SQL Database called mydb on a server with a name of myserver.database.windows.net. It's important to remember to open the firewall to your client IP address, which you do on the server.
First step is to install freetds with the ODBC driver, and its PHP connector (change php56 to the correct version of your PHP):
sudo port install freetds +odbc
sudo port install php56-odbc
Next, you need to include some lines in your configuration files:
/opt/local/etc/odbcinst.ini
[FreeTDS]
Description = ODBC for FreeTDS
Driver = /opt/local/lib/libtdsodbc.so
Setup = /opt/local/lib/libtdsodbc.so
FileUsage = 1
This tells the odbc library where to find its odbc driver.
/opt/local/etc/freetds/freetds.conf
[myserver]
host = myserver.database.windows.net
port = 1433
tds version = 7.0
This tells the freetdc library where to find your server.
/opt/local/etc/odbc.ini
[myds]
Description = Test for SQL Server on Azure
Driver = FreeTDS
Trace = Yes
TraceFile = /var/log/sql.log
Database = mydb
Servername = myserver
UserName = myusername
Password = mypassword
Port = 1433
Protocol = 7.0
ReadOnly = No
RowVersioning = No
ShowSystemTables = No
ShowOidColumn = No
FakeOidIndex = No
This creates a data source called myds pointing at your database, enabling you to connect with the following PHP:
$conn = new PDO('odbc:myds', 'myusername', 'mypassword');
If any of this doesn't work for you, first check that the freetds installation is correct using:
tsql -S myserver -U myusername -P mypassword
And then check that the ODBC specifications are OK using:
isql -v myds myusername mypassword
Thanks to https://github.com/lionheart/django-pyodbc/wiki/Mac-setup-to-connect-to-a-MS-SQL-Server, which does the equivalent job for Python and which pointed me in the right direction for all this.