Set command text to connect to MySQL using C++
Posted by: Tanya Le Sage
Date: April 03, 2012 02:48AM

Hi,

I have the following code which I am using to connect a windows console application to MySQL (using the SQLAPI++ connector).

#include <iostream>
#include <stdio.h>

#include <sqlapi.h>

using namespace std;

int main(int argc, char* argv[])
{

SAConnection con; //create connection object
try
{
con.Connect("test","root","catssss1",SA_MySQL_Client);

printf("We are connected!\n");
//con.Disconnect();
//printf("We are disconnected!\n");

}

catch(SAException &x)
{

try
{
con.Rollback();
}
catch(SAException &)
{

}

printf("%s\n", (const char*)x.ErrText());

}

SACommand cmd(& con);

cmd.setCommandText("INSERT INTO model.buildingstatus (idBuildingStatus, item, status) VALUES(:1,:2,:3)");

cmd.Param(1).setAsLong() = 3;
cmd.Param(2).setAsString() = 4;
cmd.Param(3).setAsLong() = 5;

cmd.Execute();

cin.get();
return 0;

}


It connects fine however when I try to execute the 'setCommandText' line I get this error:

Unhandled exception at 0x75c69673 in Sql_datatbase_test.exe: Microsoft C++ exception: SAException at memory location 0x001af794.

Would anybody be able to offer me any suggestions why?

I have followed the instructions on:
http://www.sqlapi.com/HowTo/commands.html

Thank you

Options: ReplyQuote


Subject
Views
Written By
Posted
Set command text to connect to MySQL using C++
3159
April 03, 2012 02:48AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.