CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2011
    Location
    India
    Posts
    333

    MySQL ODBC Connection Timeout VC++

    Hi,

    I'm using VS 2012, MySQL version 5.6 and ODBC Version 5.3.11 in Windows 7 Embedded OS 32 bit.
    I was running my application from start up. Some time data base can not connect and also time out.
    But i was checked, is mysql service running or not?. Always MySQL service is running but some times Database cannot connect.


    Code:
    BOOL openDB()
    {	  		
    	sDBName = "LMS";
    	DBUseStr = "USE `" + sDBName + "`";
    	FlushStr = "FLUSH PRIVILEGES";
    
    	sServer = "127.0.0.1";
    	sUser = "root";
    	sPassword = "password";
    
    	//sDSN.Format("Driver={MySQL ODBC 5.2 ANSI Driver};Server=127.0.0.1;User=root;Password=client;Option=4;");		
    	
    	TRY
    	{
    		sDSN.Format("Driver={MySQL ODBC 5.3 ANSI Driver};Server=" + sServer + ";User=" + sUser + ";Password=" + sPassword + ";Option=4;");
    		DB.Open(NULL,false,false,sDSN,false);	   //Some times can not come out from this line
    		
    		DB.ExecuteSQL(DBUseStr);
    		DB.ExecuteSQL(FlushStr);	
    
    	}
    	CATCH(CDBException, e)
    	{		
    		::AfxMessageBox("OpenDB_Error-"+e->m_strError);  	
    		return FALSE;
    	}
    	END_CATCH;
    
    	return TRUE;
    }
    How can i use the timeout process with this? Changed like below, but couldn't time out.

    Code:
    sDSN.Format("Driver={MySQL ODBC 5.3 ANSI Driver};Server=" + sServer + ";User=" + sUser + ";Password=" + sPassword + ";Option=4; Connection Timeout=5;");
    Regards,

    SaraswathiSrinath

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

  3. #3
    Join Date
    Nov 2011
    Location
    India
    Posts
    333

    Re: MySQL ODBC Connection Timeout VC++

    I will try and get back to you
    Regards,

    SaraswathiSrinath

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured