From: bernardofhoppe@yahoo.com
To: pgsql-odbc@postgresql.org
Subject: ODBC and multi-threading: basics
Date: 29 Jun 2004 15:35:39 -0700
Message-ID: <b62328a6.0406291435.25d90ef7@posting.google.com> (raw)
Hi,
could anyone tell me some basics about working with ODBC in a
multithreaded application?
Next are some of the questions I have, please, help me by answering
any or all of them. Your opinion would be best considered, and also
any link would be most appreciated.
Situation: I am using the ODBC API from Microsoft Visual C++ with
Windows NT 4.0. I use a single application with multiple threads that
connect all to the same database, but that might query it multiple
times (before disconnecting from it) and at different moments and with
different SQL querys from the other threads. Of course simultaneity is
a must.
Questions:
1) is ODBC a thread safe environment?
a) with any DB driver?
b) what about Access (mdb databases)?
I've heard that the Microsoft Jet Access driver version Jet 4.0
or + is thread safe. If that was to be true, how could I use the Jet
driver when I use the ODBC API in my application? Is there a way to
configure the Datasource to do so? Do you know about any link talking
about this?
2) which of these variables should I keep global so that they can be
shared among the threads? (remember they all access to the same DB)
- henv (environment handle)
- hdbc (connection handle, with which I connect to the same )
- hstmt (statement handle)
3) so, continuing question 2), which actions should be made only 1
time (for all the threads), and which should be made each time a
thread wants to access the database?
- SQLAllocEnv(&henv);
- SQLAllocConnect(henv, &hdbc);
- SQLSetConnectOption(hdbc, SQL_LOGIN_TIMEOUT, 20);
- SQLConnect(hdbc, (UCHAR*)szDataSource, SQL_NTS, (UCHAR*)szLoginName,
SQL_NTS, (UCHAR*)szPassword, SQL_NTS);
- SQLAllocStmt(hdbc, &hstmt);
- SQLPrepare(hstmt, (UCHAR*) szInst, SQL_NTS);
- SQLExecute(hstmt);
- SQLFreeStmt(hstmt,SQL_DROP);
- SQLDisconnect(hdbc);
- SQLFreeConnect(hdbc);
- SQLFreeEnv(henv);
Thanks indeed in advance and best regards.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: bernardofhoppe@yahoo.com
Subject: Re: ODBC and multi-threading: basics
In-Reply-To: <b62328a6.0406291435.25d90ef7@posting.google.com>
References: <b62328a6.0406291435.25d90ef7@posting.google.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox