Access the MSSQLServer database in Linux

Source: Internet
Author: User
Tags mssqlserver sybase client
---- Linux, as a free UNIX operating system, is used by many users based on its open source code, multi-task, and XWindow features, in addition, many enterprises use Linux as their full-featured internal network servers (WWW, FTP, email, DNS ). Enterprise intranets not only provide access to text information, but also provide access to information in enterprise relational databases. Sqlserver is used by many enterprises with its low cost, high performance, and effective integration with NT. However, Microsoft does not provide clients in UNIX, which brings difficulties to such applications. This article proposes a solution to this problem.

Install Sybase Client
---- Start with the relationship between Microsoft sqlserver and sybasesqlserver. The two companies have jointly developed sqlserverforos/2 databases on OS/2. Since then, the two companies have independently developed and upgraded systems. Sybase clients can access microsoftsqlserver.
---- Compared with other database companies, it can be said that Sybase is the most well-intentioned for Linux, although it does not provide SQL Server under Linux, but provides a free CT-LIB client, this may also be one of the reasons that many IT managers no longer consider oracle or Informix when selecting a company database. Of course the situation has changed.

---- Openclientforlinux released by Sybase is in the. Out format. Someone on the Internet converts it to ELF and dynamic link ELF format. You can find it from the following address: http://www.mbay.net /~ Mpeppler. It is best to download two versions at the same time. Dynamic Link versions are used for normal use, but some programs may need a library (libblk. a) during compilation, which is only included in elf.

---- After the download, enter the following command (assuming the current directory is/usr/tmp ):

----Tarzxvflinuxelfdynamictar.gz

---- Then move it to the/usr/local directory:

---- Mvsybase/usr/local

---- Perform the following settings to compile and use the Sybase client:

---- 1. An example of the interface file is as follows:

---- MSSQL

---- Querytcpethermysql1433

---- Wherein:

MSSQL is the server name used by the client. You can reference MSSQL later;

MySQL is the server address or name. If it is a name, the system can find its IP address;

1433 is the port number of sqlserver, the default value of microsoftsqlserver is 1433, and Sybase is 5000.
---- 2. Sybase environment variable. The content is the directory where the Sybase client is located:

---- Exportsybase =/usr/local/SYBASE

---- 3. If you compile the example in the Sybase client, you must set the environment variable sybplatform:

---- Exportsybplatform = Linux

---- Modify the server name and username and password descriptions in the header file.

Access sqlserver through the sqsh Interface
---- Sybase client provides xisql tool, but more people use sqsh, sqsh is short for sqshell, is improved iSQL, can be downloaded from the following address: http://www.voicenet.com /~ Gray /. The latest version is 1.6.0. Assume that the downloaded file is stored in the/usr/tmp directory:
----Tarzxvfsqsq1.6.0tar.gz

---- Cdsqsh1.6.0

----./Configure

---- Make; makeinstall

---- Then, install the generated Executable File sqsh to the/usr/local/bin/directory.

---- Sqsh is used as follows:

---- # Sqsh -- uusername -- ppassword -- sservername

---- Here, username and password are user names and passwords, and servername is the server name defined in the interface file (such as MSSQL in the example ).

---- Sqsh is an interactive command line interface. The command is executed by entering go. If the command is too long, it can be directly divided into several lines of books and written. Press enter to wrap it.

---- The following is an example:

---- 1> usepubs

---- 2> go

---- 1> select * fromauthors

---- 2> go uses CT-LIB To Write Applications

---- Because the Sybase Linux client does not provide DB-library, CT-library should be used to compile the application. For example, you can use CT-library to compile the application, for detailed programming instructions, refer to Sybase instructions. Use sybperl To Write Applications

---- Sybperl is a Perl extension of Sybase. You can use the Perl language to access sqlserver or write CGI programs.

---- Sybperl can get http://www.mbay.net from the following address /~ Mpeppler. The latest version is 2.9.5.

---- After obtaining the source code of sybperl, You need to modify the config file. The following are several parameters:

---- The next file to be modified is PWD, which is used for testing. Set the server name, user name, and user password to your own configuration. Then compile:

---- Perlmakefile. pl

---- Make; maketest; makeinstall

---- After the installation is successful, you can use sybperl for programming. The following is a simple example.

#! /Usr/bin/perl
Usesybase: ctlib;
$ DBH = newsybase: ctlib 'sa ', '', 'mssql ';
$ DBH-> ct_execute ("selectau_id, au_lname,
Au_fnamefrompubs.dbo.authors ");
While ($ DBH-> ct_results ($ restype) = cs_succeed ){
Nextunless $ DBH-> ct_fetchable ($ restype );
While ($ au_id, $ au_lname, $ au_fname) = $ DBH-> ct_fetch ){
Print "$ au_id-$ au_lnameau_fname/N ";
}
}

---- We can see that the database operation can be completed in just a few lines of statements.

---- The preceding sections describe how to access the MSSQLServer database in Linux and introduce basic API programming, sqsh command line access, and Perl access. In fact, other methods can be used for access in Linux, such as using JDBC at level 4. In addition to Java and JDBC, no additional software is required (the specific information is accessible to the http://www.connectsw.com ).

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.