Solved

win32 programming

Posted on 2001-06-10
8
232 Views
Last Modified: 2010-04-15
hi,

 In win32 programming  , how to connect database(oracle)

 by using win32 .wait for u r reply.









 
0
Comment
Question by:sanumakonda
8 Comments
 
LVL 5

Expert Comment

by:djbusychild
ID: 6175829
that's a pretty loaded question...
you could use odbc

check out

http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/dasdk/orcd0esl.htm
0
 
LVL 3

Expert Comment

by:kulina
ID: 6179573
sanumakonda,
Close your other questions please.

Experts,
Before you potentialy waste your time on this member check his record...
Regards.
0
 
LVL 10

Accepted Solution

by:
makerp earned 100 total points
ID: 6180932
this is a simple example ive knocked up for you, create a simple oracle database and create
a system dsn for it in control panel. the open function uses global varaibles etc so you will probably
want to chage this.

/* for db stuff */
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <stdio.h>

HENV henv;
HDBC hdbc;
int dbopen=0;

/* opens a connection using global variables , bad i know */
#define PM_DSN "your_system_dsn"
#define PM_DSN_USER "your_db_username_if_any"
#define PM_DSN_PW "your_password_if_any"

int DBopen(void)
{
    int res=0;
    RETCODE retcode;
    /*allocate the environment handle*/
    if(SQLAllocEnv(&henv)==SQL_SUCCESS)
    {
         /*allocate the connection handle*/
         if(SQLAllocConnect(henv, &hdbc)==SQL_SUCCESS)
         {
              /* Set login timeout to 5 seconds. */
              SQLSetConnectOption(hdbc, SQL_LOGIN_TIMEOUT, 5);
              SQLSetConnectOption(hdbc, SQL_CURSOR_TYPE, SQL_CURSOR_STATIC);
              /* Connect to data source */
              retcode = SQLConnect(hdbc, PM_DSN, SQL_NTS, PM_DSN_USER, SQL_NTS, PM_DSN_PW, SQL_NTS);

              if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
              {
                        res=1;
                        DATABASE_NAME = getDBName();
              }
         }
         else
         {
              SQLFreeConnect(hdbc);
         }
    }
    else
    {
         SQLFreeEnv(henv);
    }
    dbopen=res;
    return res;
}

void DBclose(void)
{
    if(dbopen)
    {
         SQLDisconnect(hdbc);
         SQLFreeConnect(hdbc);
         SQLFreeEnv(henv);
         if(DATABASE_NAME)
         {
              free(DATABASE_NAME);
         }
    }
    dbopen=0;
}
int DBexecute(char *sql,HSTMT *hstmt)
{
    int res=0;
    RETCODE retcode;

    if(SQLAllocStmt(hdbc, hstmt)== SQL_SUCCESS)
    {
         retcode=SQLPrepare(*hstmt,sql,strlen(sql) + 1);
         if(retcode==SQL_SUCCESS)
         {
              retcode=SQLExecute(*hstmt);
              if(retcode==SQL_SUCCESS)
              {
                   res=1;
              }
         }
    }
    return res;
}

void DBcloseCursor(HSTMT hstmt)
{
    SQLFreeStmt(hstmt, SQL_DROP);
}

void main()
{
    char sql[255];
    HSTMT fstmt;
    long lens;
    RETCODE retcode;
    char name[100];

    DBopen();

    sprintf(sql,"SELECT name FROM users");
    if(DBexecute(sql,&fstmt))
    {      
         SQLBindCol(fstmt,1,SQL_C_CHAR, name,sizeof(name),&lens);
         
         retcode = SQLFetch(fstmt);    
         while(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
         {
              printf("%s\n",name);
              retcode = SQLFetch(fstmt);
         }
         DBcloseCursor(fstmt);
    }
    else
    {  
         printf("DBexecute failure : %s\n",getStmtError(fstmt));    
         exit(1);
    }
    DBclose();
}
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 10

Expert Comment

by:makerp
ID: 6180937
i done it in Visual C++ 5
0
 
LVL 10

Expert Comment

by:makerp
ID: 6237087
so is see you dont bother rewarding people for their effort and work, 9 questions asked and NONE closed. i looked at your profile.
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6462674
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6800777
sanumakonda,

These questions are still open. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days. Please note that the recommended minimum for an "Easy" question is 50 points.

http://www.experts-exchange.com/jsp/qShow.jsp?ta=dbgen&qid=20114642
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cprog&qid=20230685
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cprog&qid=20132875
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cprog&qid=20132874
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cprog&qid=20109111
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cprog&qid=20107544
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20108062
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20107545
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20189956
http://www.experts-exchange.com/jsp/qShow.jsp?ta=mfc&qid=20175490
http://www.experts-exchange.com/jsp/qShow.jsp?ta=mfc&qid=20120763
http://www.experts-exchange.com/jsp/qShow.jsp?ta=mfc&qid=20120762

EXPERTS: Please leave your thoughts on this question here.

Thanks,

Netminder
Community Support Moderator
Experts Exchange
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6822138
Force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now