MSSQL per Hand
-
Hi,
wie kann ich den Zugriff auf einen MSSQL-Server ohne zuhilfenahme der MFC anstellen - so in der Art von PHP & MySql (mysql_query)?Danke schon mal
-
entweder über ODBC oder die entsprechende DB-C-Lib des MSSQL-SDK - die funktionen fangen mit dbXXXX an und sind allesamt im MSDN beschrieben ...
RockNix ///
[ Dieser Beitrag wurde am 28.04.2003 um 11:44 Uhr von RockNix editiert. ]
-
aus dem MSDN ein EX:
The following example shows the basic framework of many DB-Library for C applications. The program connects to SQL Server, sends a Transact-SQL SELECT statement to SQL Server, and processes the set of rows resulting from the SELECT.
For information about defining the target operating system prior to compiling your application, see Building Applications.
#define DBNTWIN32 #include <stdio.h> #include <windows.h> #include <sqlfront.h> #include <sqldb.h> // Forward declarations of the error handler and message handler. int err_handler(PDBPROCESS, INT, INT, INT, LPCSTR, LPCSTR); int msg_handler(PDBPROCESS, DBINT, INT, INT, LPCSTR, LPCSTR, LPCSTR, DBUSMALLINT); main() { PDBPROCESS dbproc; // The connection with SQL Server. PLOGINREC login; // The login information. DBCHAR name[100]; DBCHAR city[100]; // Install user-supplied error- and message-handling functions. dberrhandle (err_handler); dbmsghandle (msg_handler); // Initialize DB-Library. dbinit (); // Get a LOGINREC. login = dblogin (); DBSETLUSER (login, "my_login"); DBSETLPWD (login, "my_password"); DBSETLAPP (login, "example"); // Get a DBPROCESS structure for communication with SQL Server. dbproc = dbopen (login, "my_server"); // Retrieve some columns from the "authors" table in the // "pubs" database. // First, put the command into the command buffer. dbcmd (dbproc, "select au_lname, city from pubs..authors"); dbcmd (dbproc, " where state = 'CA' "); // Send the command to SQL Server and start execution. dbsqlexec (dbproc); // Process the results. if (dbresults (dbproc) == SUCCEED) { // Bind column to program variables. dbbind (dbproc, 1, NTBSTRINGBIND, 0, name); dbbind (dbproc, 2, NTBSTRINGBIND, 0, city); // Retrieve and print the result rows. while (dbnextrow (dbproc) != NO_MORE_ROWS) { printf ("%s from %s\n", name, city); } } // Close the connection to SQL Server. dbexit (); return (0); } int err_handler (PDBPROCESS dbproc, INT severity, INT dberr, INT oserr, LPCSTR dberrstr, LPCSTR oserrstr) { printf ("DB-Library Error %i: %s\n", dberr, dberrstr); if (oserr != DBNOERR) { printf ("Operating System Error %i: %s\n", oserr, oserrstr); } return (INT_CANCEL); } int msg_handler (PDBPROCESS dbproc, DBINT msgno, INT msgstate, INT severity, LPCSTR msgtext, LPCSTR server, LPCSTR procedure, DBUSMALLINT line) { printf ("SQL Server Message %ld: %s\n", msgno, msgtext); return (0); }
-
Steht da auch, welche LIBs man inkluden muss?
-
-
öhm, gehts jetzt um MSSQL oder MySQL ?
rocknix ///
-
OK, danke
-
Original erstellt von RockNix:
**öhm, gehts jetzt um MSSQL oder MySQL ?rocknix ///**
Stimmt, hab da nicht ganz richtig gelesen, aber ich denk dass die Lib von MySQL auch ganz interessant ist. Vermutlich will er einfach auf einen SQL Server zugreifen...
Wie er will

-
Die Lib hatte ich mir vorher schon angesehen, hat mir aber irgendwie nicht zugesagt

-
also zur lib von MySQL ( ab 4.0) -> habe diese selbst auch schon des öfteren angewandt und kann eigentlich nur sagen, dass sie sehr stabil läuft. ok hier und da ist einiges etwas gewöhnungsbedürftig, aber das hast du schnell im griff und - die ist für LAU

RockNix ///
-
Wieso kann man nicht mehrmals per
dbcmd(dbproc, "..."); dbsqlexec(dbproc);den gleichen SQL Befehl ausführen? Bei mir schlägt beim zweiten Mal immer dbsqlexec fehl

BTW: natürlich habe ich dbresults zwischenzeitlich aufgerufen
-
Welche lib muss man dür einen MSSQL-Server einbinden? Ich bekomme beim Borland-Builder nur jede Menge [Linker Fehler]..
