C++ ODBC Multi Connections to Same DB or not?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: C++ ODBC Multi Connections to Same DB or not?

  1. #1
    Join Date
    Jul 2009
    Posts
    153

    C++ ODBC Multi Connections to Same DB or not?

    Hello!

    I made a C++ Wrapper on top of ODBC.

    I got a Connection, and a Statement class.
    The Connection class holds the Database Connection ODBC Handle.
    The Statement class holds the Statement Handle, there can be multiple per Connection. It is made and destroyed each time a query must be done on the DB.

    Now I'm just wondering.

    I have a multithreaded application.
    Is keeping one Connection for one DB enough for the whole application? Where the different threads will make Statements based on that one Connection.
    Or is it better to keep a Connection per thread?

    Thank you

  2. #2
    Join Date
    Apr 1999
    Posts
    27,418

    Re: C++ ODBC Multi Connections to Same DB or not?

    Is your C++ wrapper itself thread safe?

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,883

    Re: C++ ODBC Multi Connections to Same DB or not?

    Quote Originally Posted by ProgrammerC++ View Post
    I have a multithreaded application.
    Is keeping one Connection for one DB enough for the whole application? Where the different threads will make Statements based on that one Connection.
    Or is it better to keep a Connection per thread?
    First of all, the database documentation should explicitly state whether its ODBC driver is able to operate in multithreaded environment. If yes, the further design is up to you, i.e. you just try and see unless there's a recommendation to do not.

    Typically database connection operation is not expensive too much, so you even may have a few connections in the same thread simultaneously.
    Best regards,
    Igor

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,652

    Re: C++ ODBC Multi Connections to Same DB or not?

    Note that some DB's will charge for or have their license restrictions based on how many connections you make, so even for a multithreaded app, there may be motivations to do all your work on a single connection (in so far as your ODBC driver allows the actions you're doing to be multithreaded on a single connection).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center