Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
mysql:it 's a db not a dbms how it 's possible?!
Does the binary log enabling affect the MySQL performances?
Strange behavior, Table Level Permission
FULLTEXT query format question
Preventing Duplicate Entries
Comparing and writing out BLOBS
Executing MySQL Commands From Within C Program
Can 't access mysql after kernel upgrade
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Downgrade Mysql from 4 to 3 23
MySQL Cluster Software
mysql test 4 1 fails with the gis test
ERROR 2002: Can 't connect to local MySQL server through socket
Getting Identity after INSERT
Update one field with more fields from another table
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
mysql have same function mthod as Oracle decode()
 
Lost connection on second stored procedure call

Lost connection on second stored procedure call

2006-12-14       - By Urscheler, Roger (COM Chantry CA)

 Back
Reply:     1     2     3  

Hi,

I have a simple stored procedure that works the first time, but when calling
the second time I get "Lost connection to MySQL server during query". Does
anybody have an idea what I am doing wrong?

When replacing the query from the SP call query << "CALL sp_get_3()"; to
query << "SELECT 3"; everything works fine.

Thanks,
Roger

SP:
DELIMITER //
DROP PROCEDURE sp_get_3 //
CREATE PROCEDURE sp_get_3()
COMMENT 'Get 3'
BEGIN
   SELECT 3;
END //
DELIMITER ;

Code:
m_con->set_option(Connection::opt_multi_statements, true);
m_con->connect(m_args.db_name, m_args.db_hostname, m_args.db_user,
m_args.db_password, m_args.db_port);

   // first call
   try
   {      
       mysqlpp::Query query = m_con->query();
       query << "CALL sp_get_3()";
       query.parse();
       cout << query.preview() << endl;
       mysqlpp::Result res = query.store();
       if (res)
       {  
           int num_results = res.size();
           for (int i = 0; i < num_results; ++i)
           {
               mysqlpp::Row row = res.fetch_row();
               if (!row.at(0).is_null())
               {
                   cout << "Result: " << row.at(0) << endl;
               }
           }
       }
   }
   catch (const mysqlpp::EndOfResults& er)
   {
       TRACE_FULL("query succeeded: %s", er.what());
   }
   catch (exception& er)
   {
       TRACE_ERROR("query failed: %s", er.what());
   }

   // second call, same code as above
   try
   {      
       mysqlpp::Query query = m_con->query();
       query << "CALL sp_get_3()";
       query.parse();
       cout << query.preview() << endl;
       mysqlpp::Result res = query.store();
       if (res)
       {  
           int num_results = res.size();
           for (int i = 0; i < num_results; ++i)
           {
               mysqlpp::Row row = res.fetch_row();
               if (!row.at(0).is_null())
               {
                   cout << "Result: " << row.at(0) << endl;
               }
           }
       }
   }
   catch (const mysqlpp::EndOfResults& er)
   {
       TRACE_FULL("query succeeded: %s", er.what());
   }
   catch (exception& er)
   {
       TRACE_ERROR("query failed: %s", er.what());
   }



Output:
CALL sp_get_3()
Result: 3
CALL sp_get_3()
query failed: Lost connection to MySQL server during query


__ ____ ____ ____ ____ ____ ____ ____ ____ ____ __
roger.urscheler@(protected) <mailto:roger.urscheler@(protected)>  :: (905)
363-6400 x 6446
Chantry Networks, Siemens AG :: www.chantrynetworks.com
<http://www.chantrynetworks.com>