Accessing the MS SQL Server database under Linux

Source: Internet
Author: User
Tags command line mssql mysql sybase sybase client versions port number linux
server| Access | data | database----Linux as a free Unix-like operating system, with its open source code, multitasking, Xwindow and other features for a large number of users, and there are many The enterprise uses Linux as its intranet's full-featured server (Www,ftp,email, DNS). The intranet of an enterprise is not only to provide access to text information, but also to provide access to information in the Enterprise relational database. SQL Server is used by many enterprises for its low cost, high performance, and efficient integration with NT, but Microsoft does not provide clients under its UNIX, which poses difficulties for such applications 。 This paper presents a solution to this problem.

Installing Sybase clients
----first from the relationship between Microsoft SQL Server and Sybase SQL Server. The two companies have jointly developed the database SQL Server for OS/2 on OS/2, and since then the two companies have independently developed upgrade systems, and Sybase clients can access Microsoft SQL Server.
----compared to other database companies, Sybase is the most benign of 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 many IT managers no longer consider Oracle or Informix when choosing a company database. Now, of course, things have changed.

----Sybase's openclient for Linux is a.out format, which has been converted to elf and dynamic-link elf formats on the Internet, and can be found at the following addresses Load: http://www.mbay.net/~mpeppler. It's best to download two versions at the same time, using dynamically linked versions when you normally use them, but some programs may need a library (LIBBLK.A) at compile time, only included in the Elf.

After downloading----, type the following command to expand (assuming the current directory is/usr/tmp):

----Tar zxvf linuxelfdynamictar.gz

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

----MV Sybase/usr/local

----compiling and using Sybase clients requires the following settings:

----1. Examples of Interface documents are as follows:

----MSSQL

----query TCP ether MySQL 1433

----of which:


MSSQL is the server name used by the client, then the MSSQL can be referenced;

MySQL is the server's address or name, if it is the name, the system can find its IP address;

1433 is the port number for SQL Server, and the default value for Microsoft SQL Server is 1433,sybase 5000.
----2. Sybase environment variables, content is the directory where Sybase clients reside:

----Export Sybase=/usr/local/sybase

----3. If you compile an example from the Sybase client, you also set the environment variable Sybplatform:

----Export Sybplatform=linux

----and modifies the description of the server name and user name and password in its header file.

Accessing SQL Server using the Sqsh interface
----Sybase Client provides the Xisql tool, but more people use Sqsh,sqsh is Sqshell abbreviation, is the improved isql, can download from the following address: Http://www.voic enet.com/~gray/. The current latest version is 1.6.0. Suppose the downloaded file is placed under the/usr/tmp directory:
----Tar zxvf sqsq1.6.0tar.gz

----CD sqsh1.6.0

----./configure

----Make;make Install

----then install the resulting executable file Sqsh into the/usr/local/bin/directory.

The use of----Sqsh is as follows:

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

----where username and password are username and password, servername is the name of the server defined in the interface file (for example, MSSQL).

----Sqsh is an interactive command-line interface, commands are executed with input go, and if the command is longer and can be written directly into a few lines, the line can be wrapped in a carriage return.

----The following is an example:

----1> use pubs

----2> Go

----1> SELECT * FROM authors

----2> go uses ct-lib to write applications

----because Sybase's Linux clients do not provide db-library, you should use Ct-library to write your application, use Ct-library to write your application for example, and Detailed programming instructions can refer to Sybase's instructions. Using Sybperl to write applications

----Sybperl is the Sybase Perl extension that uses the Perl language to access SQL Server, or to write CGI programs.

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

----Get Sybperl source code to expand, you need to modify the config file, here are a few parameters:

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

----Perl makefile.pl

----make; Make test; Make install

After the----installation is successful, you can use Sybperl to program. The following is a simple example.

#!/usr/bin/perl
Use Sybase::ctlib;
$dbh=new sybase::ctlib ' sa ', ', ' MSSQL ';
$DBH->ct_execute ("Select au_id, au_lname,
au_fname from Pubs.dbo.authors ");
while ($dbh->ct_results ($restype) = = Cs_succeed) {
Next unless $dbh->ct_fetchable ($restype);
while (($au_id, $au_lname, $au_fname) = $dbh->ct_fetch) {
Print "$au_id-$au_lname au_fname\n";
}
}
----can see that a few lines of statements, you can complete the operation of the database.

----above is a description of accessing the MS SQL Server database under Linux, which introduces basic API programming, Sqsh command line access, and Perl access. In fact, there are other ways to access Linux, such as using the fourth level of JDBC access, when in addition to Java and JDBC, no other software (specific information to access http: www.connectsw.com).


Related Article

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.