|
getting an error while compiling and running using different IDE.
Hi!,
Previously (at home) I was making C program using MVC6 (my OS is Win2K).
Then I found out that in the company that I was applying for uses an Eclipse 3.2 IDE in creating C program. Then curiousity won, so I decided to download Eclipse at home to learn how to use it (just in case that I got the job  ).
Using Eclipse is definitely different from MVC6 especially since the Eclipse uses GNU C compiler (I'm using MinGW as my complier). After few days of reading and searching on how to compile and run basic C program properly in Eclipse, I decided to migrate some of my working program compile/run in MVC to Eclipse.
Here is now my problem. The program here will log on / connect to a database. As simple as it is I'm getting a
Quote:
|
The instruction at "0x000083ac" referenced memory at "0x000083ac". The memory could not be "read".
|
popup message whenever I try to run the program compiled and run thru Eclipse. But this type of problem is never present when I'm compiling and running it thru MVC.
I'm not quite sure if this is an Eclipse bug or I need to tweek more in the Project settings in Eclipse (btw does anyone here uses Eclipse as their IDE?).
Or this could be a compiler bug (although I'm not quite sure here) my MinGW version is 3.4.2.
here are the strip down codes
main.c
#include "main.h"
struct RMConfig cfg;
int main(){
int result =0;
strcpy(cfg.db.database_name,"pnl");
strcpy(cfg.db.password,"db2admin");
strcpy(cfg.db.username,"db2admin");
result = ConnectToDB( cfg.db ) ;
if(result == 0)
{
printf("Do connection process here \n");
fflush(stdout);//tempo for eclipse display only
}
else
{
printf("Failed to connect do reconnection here! \n");
fflush(stdout);
}
return 0;
}
main.h
#include "Util.h"
extern int ConnectToDB( struct dbConfig ) ;
int main();
Util.h
#include <stdio.h>
#include <stdlib.h>
struct dbConfig
{
char database_name[ 20 ];
char username[ 20 ];
char password[ 20 ];
};
struct RMConfig{
struct dbConfig db;
};
DB.c - generated file (Embeded SQL in C)
static char sqla_program_id[162] =
{
42,0,65,68,65,75,65,73,68,66,32,32,32,32,32,32,50,65,112,75,
87,90,73,87,48,49,49,49,49,32,50,32,8,0,81,80,78,76,32,32,
32,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0
};
#include "sqladef.h"
static struct sqla_runtime_info sqla_rtinfo =
{{'S','Q','L','A','R','T','I','N'}, sizeof(wchar_t), 0, {' ',' ',' ',' '}};
#line 1 "DB.sqc"
#include <stdio.h>
#include <string.h>
#include <sqlda.h>
#include <sqlenv.h>
#include <sqlcodes.h>
#include "Util.h"
/*
EXEC SQL INCLUDE SQLCA ;
*/
/* SQL Communication Area - SQLCA - structures and constants */
#include "sqlca.h"
struct sqlca sqlca;
#line 8 "DB.sqc"
int ConnectToDB( struct dbConfig ) ;
int DisconnectFromDB( void ) ;
int CommitDB( void ) ;
int RollbackDB( void ) ;
int SQLError( char *Function, int err, struct sqlca *capointer ) ;
char logMsg[100]="";
/*
EXEC SQL BEGIN DECLARE SECTION ;
*/
#line 19 "DB.sqc"
char dbName[ 20 ] ;
char userId[ 32 ] ;
char password[ 32 ] ;
char temp[1] ;
char tempo[50] ;
/*
EXEC SQL END DECLARE SECTION ;
*/
#line 28 "DB.sqc"
int ConnectToDB( struct dbConfig db)
{
printf("Connecting to DB -> %s\n" ,db.database_name);
fflush(stdout);
printf("Using username -> %s\n" ,db.username);
fflush(stdout);
printf("Using password -> %s\n" ,db.password);
fflush(stdout);
strcpy( dbName, db.database_name ) ;
if( !strlen( db.username ) || !strlen( db.password ) ) {
printf("WARNING: Logging in database using blank username and password\n");
fflush(stdout);
/*
EXEC SQL CONNECT TO :dbName ;
*/
{
#line 47 "DB.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 47 "DB.sqc"
sqlaaloc(2,1,1,0L);
{
struct sqla_setdata_list sql_setdlist[1];
#line 47 "DB.sqc"
sql_setdlist[0].sqltype = 460; sql_setdlist[0].sqllen = 20;
#line 47 "DB.sqc"
sql_setdlist[0].sqldata = (void*)dbName;
#line 47 "DB.sqc"
sql_setdlist[0].sqlind = 0L;
#line 47 "DB.sqc"
sqlasetdata(2,0,1,sql_setdlist,0L,0L);
}
#line 47 "DB.sqc"
sqlacall((unsigned short)29,4,2,0,0L);
#line 47 "DB.sqc"
sqlastop(0L);
}
#line 47 "DB.sqc"
}
else
{
strcpy( userId, db.username ) ;
strcpy( password, db.password );
/*
EXEC SQL CONNECT TO :dbName user:userId using:password ;
*/
{
#line 53 "DB.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 53 "DB.sqc"
sqlaaloc(2,3,2,0L);
{
struct sqla_setdata_list sql_setdlist[3];
#line 53 "DB.sqc"
sql_setdlist[0].sqltype = 460; sql_setdlist[0].sqllen = 20;
#line 53 "DB.sqc"
sql_setdlist[0].sqldata = (void*)dbName;
#line 53 "DB.sqc"
sql_setdlist[0].sqlind = 0L;
#line 53 "DB.sqc"
sql_setdlist[1].sqltype = 460; sql_setdlist[1].sqllen = 32;
#line 53 "DB.sqc"
sql_setdlist[1].sqldata = (void*)userId;
#line 53 "DB.sqc"
sql_setdlist[1].sqlind = 0L;
#line 53 "DB.sqc"
sql_setdlist[2].sqltype = 460; sql_setdlist[2].sqllen = 32;
#line 53 "DB.sqc"
sql_setdlist[2].sqldata = (void*)password;
#line 53 "DB.sqc"
sql_setdlist[2].sqlind = 0L;
#line 53 "DB.sqc"
sqlasetdata(2,0,3,sql_setdlist,0L,0L);
}
#line 53 "DB.sqc"
sqlacall((unsigned short)29,5,2,0,0L);
#line 53 "DB.sqc"
sqlastop(0L);
}
#line 53 "DB.sqc"
}
SQLError( "CONNECT", SQLCODE, &sqlca ) ;
return( SQLCODE ) ;
}
int DisconnectFromDB( void )
{
char FUNC[] = "DisconnectFromDB():" ;
printf("Disconnecting from DB.\n");
fflush(stdout);
/*
EXEC SQL CONNECT RESET ;
*/
{
#line 68 "DB.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 68 "DB.sqc"
sqlacall((unsigned short)29,3,0,0,0L);
#line 68 "DB.sqc"
sqlastop(0L);
}
#line 68 "DB.sqc"
SQLError( FUNC, SQLCODE, &sqlca ) ;
return( SQLCODE ) ;
}
int CommitDB( void )
{
char FUNC[] = "CommitDB():" ;
/*
EXEC SQL COMMIT ;
*/
{
#line 78 "DB.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 78 "DB.sqc"
sqlacall((unsigned short)21,0,0,0,0L);
#line 78 "DB.sqc"
sqlastop(0L);
}
#line 78 "DB.sqc"
SQLError( FUNC, SQLCODE, &sqlca ) ;
return( SQLCODE ) ;
}
int RollbackDB( void )
{
char FUNC[]="RollbackDB():" ;
/*
EXEC SQL ROLLBACK ;
*/
{
#line 91 "DB.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 91 "DB.sqc"
sqlacall((unsigned short)28,0,0,0,0L);
#line 91 "DB.sqc"
sqlastop(0L);
}
#line 91 "DB.sqc"
SQLError( FUNC, SQLCODE, &sqlca ) ;
return( SQLCODE ) ;
}
int SQLError( char *Function, int err, struct sqlca *capointer )
{
//char buf[ 32 ] ;
char sqlState[ 1024 ] ;
char errorMsg[ 1024 ] ;
//short rc ;
int rc ;
char temp[200];
if( err ) {
if (!(strcmp("SELECT",Function)==0 && err == 100)){
printf("%s Error: SQL return code of %d.", Function, err ) ;
fflush(stdout);
if ( err != -803 ) {
rc = sqlogstt( sqlState, sizeof(sqlState), 80, capointer->sqlstate ) ;
if( sqlaintp( errorMsg, sizeof( errorMsg ), 80, capointer ) > 0 ) {
printf("%s : SQL Error message='%s'.\n",Function,errorMsg ) ;
fflush(stdout);
}
if( !rc ) {
printf("%sSQL State='%s'.\n",Function,sqlState ) ;
fflush(stdout);
}
}
}
}else {
if(memcmp(Function, "UPDATE", 6)==0){
CommitDB();
}
if(memcmp(Function, "INSERT", 6)==0){
CommitDB();
printf("INSERTION of data is successful.\n");
fflush(stdout);
}
if(memcmp(Function, "DELETE", 6)==0){
CommitDB();
printf("DELETION of data is successful.\n");
fflush(stdout);
}
if(memcmp(Function, "CONNECT",7)==0){
printf("Connection to database has been established.\n");
fflush(stdout);
}
}
return( err ) ;
}
DB.sqc where the DB.c is dereived
#include <stdio.h>
#include <string.h>
#include <sqlda.h>
#include <sqlenv.h>
#include <sqlcodes.h>
#include "Util.h"
EXEC SQL INCLUDE SQLCA ;
int ConnectToDB( struct dbConfig ) ;
int DisconnectFromDB( void ) ;
int CommitDB( void ) ;
int RollbackDB( void ) ;
int SQLError( char *Function, int err, struct sqlca *capointer ) ;
char logMsg[100]="";
EXEC SQL BEGIN DECLARE SECTION ;
char dbName[ 20 ] ;
char userId[ 32 ] ;
char password[ 32 ] ;
char temp[1] ;
char tempo[50] ;
EXEC SQL END DECLARE SECTION ;
int ConnectToDB( struct dbConfig db)
{
printf("Connecting to DB -> %s\n" ,db.database_name);
fflush(stdout);
printf("Using username -> %s\n" ,db.username);
fflush(stdout);
printf("Using password -> %s\n" ,db.password);
fflush(stdout);
strcpy( dbName, db.database_name ) ;
if( !strlen( db.username ) || !strlen( db.password ) ) {
printf("WARNING: Logging in database using blank username and password\n");
fflush(stdout);
EXEC SQL CONNECT TO :dbName ;
}
else
{
strcpy( userId, db.username ) ;
strcpy( password, db.password );
EXEC SQL CONNECT TO :dbName user:userId using:password ;
}
SQLError( "CONNECT", SQLCODE, &sqlca ) ;
return( SQLCODE ) ;
}
int DisconnectFromDB( void )
{
char FUNC[] = "DisconnectFromDB():" ;
printf("Disconnecting from DB.\n");
fflush(stdout);
EXEC SQL CONNECT RESET ;
SQLError( FUNC, SQLCODE, &sqlca ) ;
return( SQLCODE ) ;
}
int CommitDB( void )
{
char FUNC[] = "CommitDB():" ;
EXEC SQL COMMIT ;
SQLError( FUNC, SQLCODE, &sqlca ) ;
return( SQLCODE ) ;
}
int RollbackDB( void )
{
char FUNC[]="RollbackDB():" ;
EXEC SQL ROLLBACK ;
SQLError( FUNC, SQLCODE, &sqlca ) ;
return( SQLCODE ) ;
}
int SQLError( char *Function, int err, struct sqlca *capointer )
{
//char buf[ 32 ] ;
char sqlState[ 1024 ] ;
char errorMsg[ 1024 ] ;
//short rc ;
int rc ;
char temp[200];
if( err ) {
if (!(strcmp("SELECT",Function)==0 && err == 100)){
printf("%s Error: SQL return code of %d.", Function, err ) ;
fflush(stdout);
if ( err != -803 ) {
rc = sqlogstt( sqlState, sizeof(sqlState), 80, capointer->sqlstate ) ;
if( sqlaintp( errorMsg, sizeof( errorMsg ), 80, capointer ) > 0 ) {
printf("%s : SQL Error message='%s'.\n",Function,errorMsg ) ;
fflush(stdout);
}
if( !rc ) {
printf("%sSQL State='%s'.\n",Function,sqlState ) ;
fflush(stdout);
}
}
}
}else {
if(memcmp(Function, "UPDATE", 6)==0){
CommitDB();
}
if(memcmp(Function, "INSERT", 6)==0){
CommitDB();
printf("INSERTION of data is successful.\n");
fflush(stdout);
}
if(memcmp(Function, "DELETE", 6)==0){
CommitDB();
printf("DELETION of data is successful.\n");
fflush(stdout);
}
if(memcmp(Function, "CONNECT",7)==0){
printf("Connection to database has been established.\n");
fflush(stdout);
}
}
return( err ) ;
}
I do hope that I have stated my problem clearly..
again here are what I'm using
IDE: Eclipse 3.2
Compiler: MinGW 3.4.2
OS: Win2K
Any help will be surely appreciated.
regards,
jaro
p.s. to the moderators => feel free to move this thread to Miscellaneous Programming Forum if you think that this thread belongs there.
|