Install freetds in Linux

Source: Internet
Author: User
Tags driver manager

I recently used C ++ in Linux to connect to SQL Server 2005 in windows, so I had to use freetds.

Environment: System ubuntu9.04 kernel 2.6.28 GCC 4.3.3 freetds 0.91

Freetds's latest stable version is 0.91, this can download http://www.freetds.org/on the official website, you can also download at http://download.csdn.net/detail/dlutxie/4103528

Reference documents: I checked some information online, but mainly refer to the user manual http://www.freetds.org/userguide/ on the official website

After downloading the package, decompress the package:

Xgy @ Ubuntu :~ /Tmp $ tar xvf freetds-0.91.tar.gz

Xgy @ Ubuntu :~ /Tmp $ CD freetds-0.91/
Xgy @ Ubuntu :~ /Tmp/freetds-0.91 $./configure -- prefix =/usr/local/freetds0.91 -- enable-msdblib -- With-tdsver = 7.1

-- Prefix =/usr/local/freetds0.91: freetds will be installed in the/usr/local/freetds0.91 directory

-- Enable-msdblib: allows the Microsoft database function library.

-- With-tdsver = 7.1 This is the Protocol version of the specified TDs. If you do not specify that only the tds5.0 version is installed, there is a lot of information on the Internet. Here we write 8.0. In fact, the highest version of TDS is 7.2, and it will not be updated later. So if we write 8.0, We will install 5.0, in addition, TDS has version 7.2, but it can only be written to version 7.1. If it is 7.2, it is installed in version 5.0. This can be used. /configure -- Help. After the output, you can see a line like this: -- With-tdsver = version TDS protocol version (4.2/4.6/5.0/7.0/7.1) [5.0]

For more detailed configuration, see: http://www.freetds.org/userguide/config.htm

In addition, I did not install the ODBC driver manager or ODBC driver before installing freetds.

 

Next we will compile and install:

Xgy @ Ubuntu :~ /Tmp/freetds-0.91 $ make

Root @ Ubuntu:/home/xgy/tmp/freetds-0.91 # make install // note that this is executed by the root user.

Next, configure some environment variables.

Edit the. bashrc file in your home directory. Add the following content to the last line of the file:

Export Path = $ path:/usr/local/freetds0.91/bin

Export LD_LIBRARY_PATH = $ LD_LIBRARY_PATH:/usr/local/freetds0.91/lib

Run the following command: source. bashrc // to make the settings take effect.

You can change the environment variable LD_LIBRARY_PATH to the configuration file/etc/lD. So. conf. Add/usr/local/freetds0.91/lib to the last line of the file.

If the file/etc/lD. So. conf is changed, run ldconfig under the root user to make the configuration take effect immediately.

If you have any questions about the configurations of these two variables, it is best to take a good look at this article:

There is information on the Internet that I still need to configure the freetds variable. I have tested it, so I don't need to configure this variable.

Now let's take a look at your installation. Run the following command: tsql-C output:

 

We can see that the freetds version is 0.91. The freetds. conf configuration file is in the/usr/local/freetds0.91/etc directory, and the TDS version is 7.1 !! When I start configure -- With-tdsver selects 8.0 and 7.2, the output tdsversion value is 5.0. When I use this configuration to connect to sqlserver2005 in windows, run the following command:

Xgy @ Ubuntu :~ $ Tsql-H 192.168.13.153-p1433-U sa-P 123456 // the following error occurs:

If "unexpected EOF from the server" appears, it is likely that the version configuration of TDS is incorrect. For this error and the version configuration of TDS, see the following documents:

Http://www.freetds.org/userguide/choosingtdsprotocol.htm#TAB.PROTOCOL.BY.PRODUCT

Http://www.freetds.org/userguide/confirminstall.htm#E.G.BADNAME

Next to the freetds. conf file configuration, this can refer to: http://www.freetds.org/userguide/freetdsconf.htm#TAB.FREETDS.CONF

Add the following content at the end of the file:

[Seamus-PC]

Host = 192.168.13.153 // sqlserver machine name or IP address

Port = 1433

TDS version = 7.1

Note: The content in the brackets of [Seamus-PC] can be written at will.

The connection is tested. The command is: xgy @ Ubuntu :~ $ Tsql-h192.168.13.153-P 1433-U sa-P 123456

First, run the ping command to ensure that the two systems can communicate. If Linux is installed in a virtual machine, the NIC needs to be configured in Nat mode (the two systems are on the same host) or Bridge Mode (Linux and Windows are on two hosts)

If the SQL server2005 service is not started, the following error may occur:

In addition, remember to enable the server's TCP/IP protocol: Start-> Microsoft SQL server2005-> Configuration tool-> SQL Server Configuration Manager, as shown in:

Enable the TCP/IP protocol and then restart the service.

The following figure shows that if I have not enabled the TCP/IP protocol and the TDS version is 5.0

Xgy @ Ubuntu :~ $ Error in tsql-H 192.168.13.153-P 1433-U sa-P 123456:

If the connection is successful, a prompt is displayed:>, and then you can enter the SQL statement. The following is my execution:

Student is a table in my database pctest (default database)

At this point, freetds is installed in Linux and connected to SQL server2005 in windows !!

Next, write a program to connect to the database. For details, refer. You can also download from the following link, the example is the same, but I added the Note: http://download.csdn.net/detail/DLUTXIE/3668501,
Also refer to http://msdn.microsoft.com/en-us/library/aa936982 (V = SQL .80). aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.