This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes General Computing and the fly likes database connectivity with c++ application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » General Computing
Bookmark "database connectivity with c++ application" Watch "database connectivity with c++ application" New topic
Author

database connectivity with c++ application

himanshu singhal
Greenhorn

Joined: Apr 01, 2003
Posts: 2
hi
i m not able to connect to MS-Acees from c++ application.if anybody can solve my problem
Thanks
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Hi Himanshu -
I'll move this to General Computing, as it seems a better fit there.
If you are getting some error information back from the connection attempts, why not post them in a message here? There are all sorts of things that can go wrong between two processes trying to connect. While we've all experienced the kind of problem you're having now, it's impossible to know what to advise without a little more background information.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Sameer Jamal
Ranch Hand

Joined: Feb 16, 2001
Posts: 1870
hi try this
#include <windows.h>
#include <sqlext.h>
#include <stdio.h>

int main(void)
{
HENV hEnv = NULL;
// Env Handle from SQLAllocEnv()
HDBC hDBC = NULL;
// Connection handle
HSTMT hStmt = NULL;
// Statement handle
UCHAR zDSN[SQL_MAX_DSN_LENGTH= "datasourcename";
// Data Source Name buffer
UCHAR* szUID = NULL;
// User ID buffer
UCHAR* szPasswd = NULL;
// Password buffer
UCHAR szModel[128];
// Model buffer
sDWORD cbModel;
// Model buffer bytes recieved
UCHAR szSqlStr[] = "Select * From table Where field='value'";
//SQL string
RETCODE retcode;
// Return code

// Allocate memory for ODBC Environment handle
SQLAllocEnv (&hEnv);

// Allocate memory for the connection handle
SQLAllocConnect (hEnv, &hDBC);

// Connect to the data source "datsourcename"
//using userid and password.
retcode = SQLConnect (hDBC, szDSN, SQL_NTS, szUID, SQL_NTS, szPasswd, SQL_NTS);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
// Allocate memory for the statement handle
retcode = SQLAllocStmt (hDBC, &hStmt);

// Prepare the SQL statement by assigning it to
//the statement handle
retcode = SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr));

// Execute the SQL statement handle
retcode = SQLExecute (hStmt);

// Project only column 1 which is the models
SQLBindCol (hStmt, 1, SQL_C_CHAR, szModel, sizeof(szModel), &cbModel);

// Get row of data from the result set defined
//above in the statement
retcode = SQLFetch (hStmt);

while (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
printf ("\t%s\n", szModel);
// Print row (model)
retcode = SQLFetch (hStmt);
// Fetch next row from result set
}

// Free the allocated statement handle
SQLFreeStmt (hStmt, SQL_DROP);

// Disconnect from datasource
SQLDisconnect (hDBC);
}

// Free the allocated connection handle
SQLFreeConnect (hDBC);

// Free the allocated ODBC environment handle
SQLFreeEnv (hEnv);
return 0;
 
GeeCON Prague 2014
 
subject: database connectivity with c++ application