X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A3D8FD1B23E for ; Tue, 29 Jun 2004 19:44:36 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 67645-05 for ; Tue, 29 Jun 2004 22:44:30 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id BD222D1B1AA for ; Tue, 29 Jun 2004 19:44:27 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i5TMiRQC072505 for ; Tue, 29 Jun 2004 22:44:27 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i5TMZeP3071415 for pgsql-odbc@postgresql.org; Tue, 29 Jun 2004 22:35:40 GMT From: bernardofhoppe@yahoo.com (zzzmito) X-Newsgroups: comp.databases.postgresql.interfaces.odbc Subject: ODBC and multi-threading: basics Date: 29 Jun 2004 15:35:39 -0700 Organization: http://groups.google.com Lines: 47 Message-ID: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: groups-abuse@google.com To: pgsql-odbc@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.5 tagged_above=0.0 required=5.0 tests=FORGED_YAHOO_RCVD X-Spam-Level: X-Archive-Number: 200407/5 X-Sequence-Number: 4138 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.