LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-13-2004, 09:52 AM   #1
sleepymish
LQ Newbie
 
Registered: Oct 2003
Posts: 16

Rep: Reputation: 0
Question MySQL + ODBC + C programming qusestion


Hi,

I'm new to the database and ODBC world and I have a question.
When I run the following code I get the error below. I googled and searched around, which said my connection might be lost or my query is too big. But neither of those cases are true. I'm wondering if anyone can find the mistake in my code.

THANKS!!!

Michelle



*************** ERROR ***********************************
mainSQLState HY000
MySQL server has gone away
*************** ERROR ***********************************




*************** CODE BEGINS******************************
// Insert Query
void cDatabase::Insert(void)
{
SQLRETURN rc = SQL_SUCCESS;

// used for SQLGetDiagRec
SQLINTEGER NativeError;
SQLCHAR SQLState[6];
SQLCHAR ErrorMsg[255];
SQLSMALLINT ErrorMsgLength;

// query statement
SQLCHAR* statement = (SQLCHAR*)"Insert into dummy values ('2004-01-09')";

// allocate a SQL statement handle
rc = SQLAllocHandle(SQL_HANDLE_STMT, m_hDbc, &m_hStmt);
printf("allocating SQL statement handle\n");

if (rc == SQL_SUCCESS)
{
// rc=SQLPrepare(m_hStmt, statement, 39);
rc=SQLExecDirect(m_hStmt, statement, SQL_NTS);

// rc=SQLExecute(m_hStmt);

if (rc == SQL_SUCCESS)
printf("insert successful!\n");
if (rc == SQL_ERROR)
{
printf("insert unsuccessful! Error!\n");
SQLGetDiagRec(SQL_HANDLE_STMT, m_hStmt, 1, SQLState, &NativeError, ErrorMsg, 255, &ErrorMsgLength);
printf("mainSQLState %s\n", SQLState);
printf("%s\n\n", ErrorMsg);
}
}
}

*************** CODE ENDS******************************
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL ODBC driver fails when trying to add a DSN to MySQL banjoman Linux - Software 0 01-24-2005 09:59 AM
ODBC/MySQL/OpenOffice linuxfond Linux - Newbie 1 05-09-2004 04:27 PM
ODBC Programming Question with SQLBulkOperations sleepymish Programming 0 01-27-2004 03:28 PM
ODBC connection to MySQL darius Linux - Software 2 09-29-2003 06:40 PM
ODBC driver for MySql baburaj General 1 06-29-2002 10:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration