Recently I have to connect to MSSQL to communicate between two server. One in Linux and the other one is Window Server. But this isn't easy as work on localhost. As I know the xampp in window doesn't have odbc driver b'coz it already there. Then after a while I managed to find the solution.
Here what i found:
Step 1:
Open Terminal
Step 2:
Install unixODBC and freetds
yum install unixODBC
yum install freetds
yum install freetds
Step 3:
open the odbc.ini in etc folder and paste this code
[MSSQL]
Driver=FreeTDS
Description=MS SQL Test
Trace=No
Server= 121.0.0.1
Database= myDB
Port=1433
TDS_Version = 8.0
Driver=FreeTDS
Description=MS SQL Test
Trace=No
Server= 121.0.0.1
Database= myDB
Port=1433
TDS_Version = 8.0
Note : Change the the server into your server (window).
Step 4:
open the odbcinst.ini in etc folder
and paste this code
[FreeTDS]
Description = FreeTDS driver
Driver = /usr/lib64/libtdsodbc.so.0
Setup = /usr/lib64/libtdsS.so.2
Trace = Yes
TraceFile = /tmp/freetds.log
FileUsage = 1
UsageCount =1
[ODBC]
DEBUG=1
TraceFile=/root/sqltrace.log
Trace=Yes
Description = FreeTDS driver
Driver = /usr/lib64/libtdsodbc.so.0
Setup = /usr/lib64/libtdsS.so.2
Trace = Yes
TraceFile = /tmp/freetds.log
FileUsage = 1
UsageCount =1
[ODBC]
DEBUG=1
TraceFile=/root/sqltrace.log
Trace=Yes
Note : Please check the exact location for Driver/Setup in your Linux Server.
Step 5:
open the freetds.conf in etc folder
and paste this code
[MSSQL]
host = 127.0.0.1
port = 1433
tds version = 8.0
host = 127.0.0.1
port = 1433
tds version = 8.0
Note : Change the the server into your server (window).
Step 6:
then you may test the connection with this code
isql -v MSSQL sa password
you will get this
[root@localhost]# isql -v MSSQL sa password
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
sa - refer to the username of the SQL authentication
password - refer to the password
of the SQL authentication
Step 7:
Create test page in php
<?php
// connect to DSN MSSQL with a user and password
$connect = odbc_connect("MSSQL", "sa", "password") or die
("couldn't connect");
$result = odbc_exec($connect, "SELECT Identity_No, Name FROM dbo.user");
while(odbc_fetch_row($result)){
print(odbc_result($result, "Identity_No") .
' ' . odbc_result($result, "Name") . "<br>\n");
}
odbc_free_result($result);
odbc_close($connect);
?>
// connect to DSN MSSQL with a user and password
$connect = odbc_connect("MSSQL", "sa", "password") or die
("couldn't connect");
$result = odbc_exec($connect, "SELECT Identity_No, Name FROM dbo.user");
while(odbc_fetch_row($result)){
print(odbc_result($result, "Identity_No") .
' ' . odbc_result($result, "Name") . "<br>\n");
}
odbc_free_result($result);
odbc_close($connect);
?>
If you get the result, that mean you has successfully connected to MSSQL. But if you don't, please try to recheck each of the file (freetds.conf, odbc.ini, odbcinst.ini) in their exact location. This state is the harder one, no one ever told me about the location. I got stuck in there also. But it did figure it out soon. Try to locate the odbc file with this
odbcinst -j
you will get this information about the ODBC driver that you install earlier.
unixODBC 2.2.11
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
USER DATA SOURCES..: /root/.odbc.ini
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
USER DATA SOURCES..: /root/.odbc.ini
That will solve your problem..Hope you can make it.
I love open source..♥♥♥
Hello
ReplyDeleteThanks for the tutorial.
But I have this error when I tried to conecto with php
"PHP Warning: odbc_connect(): SQL error: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source, SQL state S1000 in SQLConnect"
It probably not find your odbc.ini & odbcinst.ini
DeleteDifferent OS has different location.
My first try in Centos. Then I try to implement in Suse. It give me like this warning. Then I try to figure out where the files location is calling and that will be the solution. It's work. Try to works on the OS environment.
how do i test on OS environemnt, getting same error. it connect from command line but throw error from script
DeleteHello, thanks for the tutorial!
ReplyDeleteI got the following error:
"Fatal error: Call to undefined function odbc_connect()"
Have you restart the service?
Deletesame here.. only in php not work but in centos ssh its work
DeleteΗello there! Do you use Twitter? I'd like to follow you if that would be ok. I'm undoubtedly enjоуing your blog and look forward to nеw updаtes.
ReplyDeletehttр://www.dfw-taxicab.com/2011/09/why-уou-need-a-taхі-service-in-irving-tх/
My site :: limo service Irving tx
A brave lady I knew that this is probably worse then I have been drunk in years because I might have broken my
ReplyDeletewashing machine. I hope this article I am even contemplating
getting pregnant demonstrates the seriousness of emetophobia.
Emetophobia, the anxiety or my big phobia. Wing gently walked him down, and I didn't feel good AT ALL on pushing the baby out because of this it is possible to die from such horror. It may very well be worse.
Have a look at my web blog - emetophobia treatment Perley
I coulԁ not resist сommenting.
ReplyDeleteExcеptionally ωell written!
Feel free to visit my homepаge ... Irving Cab
Ιt's a pity you don't have а donate button! I'd certainly donate to this brilliant blog! I suppose for now i'll settle for boοkmаrking and adding yοuг RSS feed to my Google
ReplyDeleteaccount. I loοk forward to new updаtes and will talk about this
blog ωіth my Facebook gгoup. Ϲhat soon!
Here is my blog devis peinture
Wow that was unusuаl. I just ωrοte an inсredibly lоng сomment but
ReplyDeleteafteг І clіcked submit mу comment ԁidn't show up. Grrrr... well I'm not writing
all thаt oѵer agаin. Аnуways, just wanted to ѕay eхсellent blog!
Here іѕ my pagе ... meuble salle de bain pas cher
Neat blog! Is your theme custom made or did you download it from somewhere?
ReplyDeleteA design like yours with a few simple adjustements would really make my blog shine.
Please let me know where you got your design. Thank you
Visit my web site - diy home improvement ()
Awesome article.
ReplyDeletemy blog post - barbie life in the dreamhouse
itswork .. in centos but in php its error Fatal error: Call to undefined function odbc_connect()
ReplyDeleteis there any configuration on php.ini ???
Excelent tutorial, the configuration is very easy.. thanks
ReplyDeletegolden goose
ReplyDeletegolden goose outlet
golden goose sneakers
yeezy shoes
golden goose
golden goose outlet
supreme clothing
supreme t shirt
supreme clothing
golden goose sneakers
goyard
ReplyDeletesupreme hoodie
yeezy
golden goose sneakers
golden goose
goyard
golden goose outlet
golden goose
supreme t shirt
goyard handbags