1 OverviewConnecting to MSSQL in Linux is very painful because Microsoft did not provide any interfaces to developers. Fortunately, MSSQL is derived from Sybase, freetds is the underlying driver of the database. It is very convenient to use the freetds library for development. Freetds can connect to Sybase and ms SQL Server databases.
2 install, configure, and testOfficial site: http://www.freetds.org version: 0.64 $ tar-zxvf freetds-stable.tgz $. /configure -- prefix =/usr/local/freetds $ make $ su root $ make install $ tsql-H 2.2.2.2-P 1433-U test-P testtsql Description: H: database iP P: Database port U: User Name P: Password
3 C/C ++ development in Linux
3.1 Use freetds's own program for developmentLocation in freetds-0.64/src/apps $ make clean $ make
3.2 rapid development using freetds LibraryTestsybase. C # include <stdio. h> # include <string. h> # include <stdlib. h> # include <unistd. h> # include <sybfront. h> # include <sybdb. h> int main (void) {char szusername [32] = "test"; char szpassword [32] = "test"; char szdbname [32] = "test "; char szserver [32] = "2.2.2.2: 1433"; // initialize DB-library dbinit (); // connect to the database loginrec * loginrec = dblogin (); dbsetluser (loginrec, szusername); dbsetlpwd (loginrec, szpassword ); Dbprocess * dbprocess = dbopen (loginrec, szserver); If (dbprocess = fail) {printf ("ASB> conect ms SQL Server fail/N"); Return 0 ;} else {printf ("ASB> connectems conect ms SQL Server success/N");} If (dbuse (dbprocess, szdbname) = fail) {printf ("ASB> Open Database Name fail/N");} else {printf ("ASB> Open Database Name success/N ");} // query the database dbcmd (dbprocess, "select ID, begintime, description from Alarms "); If (dbsqlexec (dbprocess) = fail) {printf (" ASB> query alarms table error/N ");} dbint result_code; char szid [1024]; char szbegintime [1024]; char szdescription [1024]; int rows = 0; while (result_code = dbresults (dbprocess ))! = No_more_results) {If (result_code = succeed) {dbbind (dbprocess, 1, charbind, (dbint) 0, (byte *) szid); dbbind (dbprocess, 2, charbind, (dbchar) 0, (byte *) szbegintime); dbbind (dbprocess, 3, charbind, (dbchar) 0, (byte *) szdescription); While (dbnextrow (dbprocess )! = No_more_rows) {printf ("ASB> id = % s/n", szid); printf ("ASB> szaid = % s/n", szbegintime ); printf ("ASB >>szbegintime = % s/n", szdescription) ;}}// close the database connection dbclose (dbprocess); Return 0 ;}compile: gcc-O testsybase. c. /src/dblib /. libs/libsybdb. A