Access the MSSQLServer database under Linux

zhaozj2021-02-11  185

---- Linux as a free UNIX class operating system, with its open source, multitasking, X -Window, etc., and many companies use Linux to serve as a full-feature of its internal network. Servers (WWW, FTP, Email, DNS). The enterprise's internal network not only provides access to text information, but also provides access to information in the business relationship database. SQLServer uses its low cost, high performance, and effective integration with NT for many companies, but Microsoft does not provide clients under its UNIX to bring difficulties for such applications. This article has put forward this problem solution.

Install the Sybase client

---- First of all from MicrosoftSqlServer and SybaseSQLServer. Two companies have jointly developed the database SQLSerForos / 2 on OS / 2. Thereafter, the two companies have independently develop upgrade systems, and Sybase's client can access MicrosoftSqlServer.

---- Compared with other database companies, you can say that Sybase has the most good meaning of Linux, which does not provide SQL Server under Linux, but provides free CT-LIB clients, which may also be many ITs. Managers do no longer consider one of Oracle or Informix when the company's database is selected. Of course, the situation is now changed.

---- Sybase released OpenClientforlinux is a.out format, someone translates it to ELF and dynamic links on the ELF format to download: http://www.mbay.net/ ~ MPEppler. It is best to download two versions simultaneously. Use the dynamic link version when used, but some programs may need a library (libblk.a) when compiling, only in ELF.

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

---- Tarzxvflinuxelf DynamicTar.gz

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

---- MVSYBASE / USR / LOCAL

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

----1. The interface file is as follows:

---- MSSQL

---- querytcpethermysql1433

----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, and the default value of MicrosoftSql 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:

---- ExportsybPlatform = Linux

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

Access SQLServer using the SQSH interface

---- Sybase client provides XISQL tools, but more people use SQSH, Sqsh is the abbreviation of Sqshell, is an improved ISQL, downloaded from the following address: http://www.voicenet.com/ ~ Gray /. The current latest version is 1.6.0. Assume that the downloaded file is placed in / usr / TMP directory:

---- Tarzxvfsqsq1.6.0tar.gz ---- CDSQSH1.6.0

----./configure

---- Make; MakeInstall

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

---- SQSH is used as follows:

---- # SQSH - UUSERNAME - PPASSWORD - SSERVERNAME

---- UserName and Password are user names and passwords, ServerName is the server name defined in the Interface file (such as MSSQL in the example).

---- SQSH is the interactive command line interface, commands with input go, if longer can be directly divided into several lines, to enter the bank.

---- as follows is an example:

---- 1> Usepubs

---- 2> Go

---- 1> SELECT * FROMAUTHORS

---- 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, using CT-Library writing applications, and detailed programming instructions can be referred to Sybase. Write applications with Sybperl

---- SybperL is Sybase's Perl extension, you can use Perl language to access SQL Server or write CGI programs.

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

---- After obtaining 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, user password is set to its own configuration. Then compile:

----Perlmakefile.pl

---- MakeTest; MakeInstall

---- After the installation is successful, you can use SybperL to program. Here 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";

}

}

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

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

New Post(0)