Build your professional network on facebook via our app Go to app
 
<< Prev  4 of 6 in Topic  Next >>
Topic : SQL Server Programming
  Rate : 
 
Industry : IT Services
Functional Area : Application Software
Keywords : sql
Activity: Question posted: 04 09 2009 11:30:33 +0000, 3 answers, 706 views, last activity 07 06 2010 20:18:08 +0000
 
Share
 
 
 
 

I am working on a project and i want to connect sql server and C++.I am using c++ as front end language and SQL as back end language

 
  Answered by     chendhil , SQL DBA, Zenith Infotech  | 02 24 2010 21:02:42 +0000
[ Delete ]
[ Edit ]
Not Rated

 

#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);
}

  Answered by     Atul Katrajkar, Team Leader -(Technical), Syntel Ind Pvt Ltd  | 04 21 2009 07:07:45 +0000
[ Delete ]
[ Edit ]
Not Rated

As I think by using PRO*C you can access data base through  C++.

  Answered by     Kamalesh Tripathi, Project Manager, Sapient Corporation  | 04 09 2009 13:04:36 +0000
[ Delete ]
[ Edit ]
Not Rated

Use something like this:
SQLSMALLINT i;

unsigned char buffer[256];
SQLDriverConnect(hDbc,hWnd,(unsigned
char*)"DSN=mydatabase;UID=sa",SQL_NTS,buffer,sizeof buffer,&i,
SQL_DRIVER_COMPLETE_REQUIRED);

hope this is right...

 
Rate:
Submit
Get the Best from Us !
Viewers also viewed
Dynamic Management Views   The dynamic management views (DMV’s) in SQL Server 2005 are designed...
 
11 referals 6 comments, 1828 views
Though media vs Self
 
157 referals 105 arguments, 3005 views
Hi friends !!!                               We know, every company today requires a software to...
 
826 referals 29 arguments, 822 views
more...  
Unanswered Questions (11)
I mean that it sector totally depends on outsourcing.But it might happen that in future other...
 
0 referals 0 answers, 0 views
Hi,  I need some information ..  How can you understand and control costs? and  Is there an...
 
1 referals 1 answers, 31 views
To brief on myself, I am P2P, PMP, MBA(IT), B.E.(CS), Oracle SCWCD, J2EE Professional with 8+...
 
0 referals 0 answers, 0 views
More From Author
Should E-Marketing be abolished or not? The crime rate is growing to heights on daily basis and if this continues,online transactions are also not secured any more.
How to connect SQL server and C++
more...