C++ connect to MySQL

This is a discussion on C++ connect to MySQL within the C++ Programming forums, part of the General Programming Boards category; I have a program that access MySQL. I use the following method to connect to MySQL. Code: void ConnectDB() { ...

  1. #1
    thl
    thl is offline
    Registered User
    Join Date
    Nov 2006
    Posts
    1

    C++ connect to MySQL

    I have a program that access MySQL.

    I use the following method to connect to MySQL.

    Code:
    void ConnectDB()
    {
      HENV hEnv = NULL;
      HDBC hDBC = NULL;
      RETCODE retcode;        
    			
      char* szUserName = (char*) sLogin.c_str();
      char* szPassword = (char*) strdbPassword.c_str();
      char* szDNS = (char*) sDSN.c_str();
            
            
      SQLAllocEnv(&hEnv);
      SQLAllocConnect (hEnv, &hDBC);
      retcode = SQLConnect (hDBC, (UCHAR*)szDNS, SQL_NTS, (UCHAR*)  szUserName, SQL_NTS, (UCHAR*)szPassword, SQL_NTS);
            
      if (retcode1 == SQL_SUCCESS || retcode1 == SQL_SUCCESS_WITH_INFO)
      {
         printf("Database connect sucessfully.\n");
      } 
      else
      {
        printf("Database connect fail.\n");
      }
    
      SQLDisconnect( hDBC );
      SQLFreeConnect( hDBC );
      SQLFreeEnv( hEnv );
    }
    
    int main()
    {
      while( 1 )
      {
        ConnectDB();
        Sleep(1000);
      }
    
      return 0;
    }
    When I run this program, I monitor the memory usage through Task Manager,
    I found that the memory usage will increase.

    I have done some reserch about the ODBC connection method, some claim that this method will cause memory leak some how.

    Can anyone help me on this?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    > Can anyone help me on this?
    Maybe post it on the MySQL forum where there are likely to be a high concentration of people with vastly more experience of MySQL.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to connect mysql in mfc.
    By sgh in forum C++ Programming
    Replies: 1
    Last Post: 12-27-2008, 11:41 PM
  2. MySQL libraries
    By csonx_p in forum C++ Programming
    Replies: 6
    Last Post: 10-02-2008, 02:23 AM
  3. Connect to server and get info from mysql db.
    By Sam Granger in forum C++ Programming
    Replies: 2
    Last Post: 01-26-2006, 05:11 AM
  4. Client timed-out once on connect(), can never connect() again
    By registering in forum Networking/Device Communication
    Replies: 6
    Last Post: 10-28-2003, 02:46 PM
  5. MySQL Connect from Outside Computer
    By juschillin in forum Windows Programming
    Replies: 0
    Last Post: 09-27-2002, 08:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21