As a free UNIX operating system, Linux is widely used by many users with its open source code, multi-task, and X-window 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 Sybase sqlserver. 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 a. Out format. Someone on the Internet converts it to ELF and dynamic link ELF format, you can find it from the following address download: 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 ):
Tar zxvf linuxelfdynamic.tar.gz
Then move it to the/usr/local directory:
Mvsybase/usr/local
To compile and use the Sybase client, perform the following settings:
1. An example of the interface file is as follows:
MSSQL
Querytcpethermysql1433
Where:
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 also set the environment variable sybplatform:
Exportsybplatform = Linux
Modify the server name, user name, 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:
tar zxvf sqsq1.6.0.tar.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 using the input go. If the command is too long, it can be directly divided into several lines of books and written. Just 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, you should use CT-library to write applications. For example, you can use CT-library to write applications, 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"; } } |
It can be seen 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 ).