Access MS SQL Server Database Under Linux

zhaozj2021-02-16  114

Linux as a free UNIX class operating system, with its open source, multitasking, XWindow, etc.

Adopted for many users, and many companies use Linux to serve as a full-featured server of its internal network (WWW, F

TP, EMAIL, DNS. The internal network of enterprises not only provide access to text information, but also provide the number of corporate relationships.

According to the access to the information in the library. SQL Server uses its low cost, high performance, and effective integration with NT.

Multi-enterprise is used, but Microsoft does not provide clients under its UNIX to bring difficulties for such applications. This article

Solutions for this issue are put forward.

Install the Sybase client

First, from the relationship between Microsoft SQL Server and Sybase SQL Server. Two companies have developed

Database SQL Server for OS / 2 on OS / 2, after which two companies have independently develop upgrade system, Sybase customers

The end can access Microsoft SQL Server.

Compared with other database companies, it can be said that Sybase has the most kindness to Linux, although it does not provide Lin

SQL Server under UX, but provides free CT-LIB clients, which may also be that many IT managers are

One of the reasons for Oracle or Informix is ​​no longer considered when the company's database is selected. Of course, the situation is now changed.

The OpenClientforlinux released by Sybase is a.out format, and someone turns it to the Internet.

ELF and dynamic links of ELF formats can be found from the following addresses:

http://www.mbay.net/~mpeppl

ER. It is best to download two versions simultaneously. Use dynamic links when used, but some programs can be compiled.

You can need a library (libblk.a), only in 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

Compile and use the Sybase client to make the following settings:

1. The interface file is as follows:

MSSQL

Query TCP Ether MySQL 1433

among them:

MSSQL is the server name used by the client, and then references MSSQL;

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

1433 is the port number of SQL Server, the default value of Microsoft SQL Server is 1433, 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 have to set the environment variable Sybplatform:

Export sybplatform = linux

And modify the description of the server name and username and password in its header file.

Use the SQSH interface to access SQL Server

The Sybase client provides XISQL tools, but more people use SQSH, SQSH is the abbreviation of Sqshell

It is an improved ISQL that can be downloaded from the following address:

http://www.voicenet.com/~gray/. Current most

The new version is 1.6.0. Assume that the downloaded file is placed in / usr / TMP directory:

TAR ZXVF SQSQ 1.6.0 TAR.GZCD SQSH 1.6.0

./configure

Make; Make Install

Then, install the generated executable SQSH to the / usr / local / bin / directory.

The use of SQSH is as follows:

# SQSH - UUSERNAME - PPASSWORD - SSERVERNAME

Where username and password are user names and passwords, ServerName is defined in the interface file.

Server name (such as MSSQL in the example).

Sqsh is an interactive command line interface, command to enter GO, if the command can be directly divided into several lines

Written, go back to the loan.

As is an example:

1> USE PUBS

2> Go

1> SELECT * AUTHORS

2> Go uses CT-LIB writing applications

Since Sybase's Linux client does not provide DB-Library, CT-Library should be used to write applications.

Program, use CT-Library writing applications to refer to the example, detailed programming instructions can refer to Sybase

Bright. Write applications with Sybperl

Sybperl is Sybase's Perl extension, you can use Perl language to access SQL Server, or write CGI

sequence.

Sybperl can get from the following address

http://www.mbay.net/~mpeppler. The current latest version is 2

.9.5.

After getting the source code of Sybperl, you need to modify the config file, the following is a few parameters:

The next file to be modified is PWD, which is used to test, the server name, user name,

The account order is set to your own configuration. Then compile:

Perl makefile.pl

Make; Make Test; Make Install

After the installation is successful, you can use SybperL to program. Here 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 == cs_succeed) {

Next UNS $ dbh -> ct_fetchable ($ restype);

While ($ AU_ID, $ AU_LNAME, $ AU_FNAME) = $ dbh -> ct_fetch) {

Print "$ AU_ID - $ AU_LNAME AU_FNAME / N";

}

}

It can be seen that a few rows of statements can be done to complete the operation of the database.

转载请注明原文地址:https://www.9cbs.com/read-10425.html

New Post(0)