|
|
Thanks, good link!
regards,
George
|
|
|
|
|
|
It means you have a bug in your code, why not try the debugger ?
|
|
|
|
|
thanks for reply sir
i use debugger and debugger shows this error in msgbox
and my code is as sir :
int i;
MYSQL *myDB;
MYSQL_RES *res;
MYSQL_ROW row;
CString user,pass,aqp;
if ((myDB = mysql_init((MYSQL*) 0)) &&
mysql_real_connect(myDB,"localhost","root",NULL,NULL,3306,NULL,NULL))
{
if ( mysql_select_db( myDB,"gourav") < 0 )
{
MessageBox("Can't select the database !\nTry later.");
goto exit_here;
}
else
{
MessageBox("Can't connect !\nPlease try later.") ;
goto exit_here;
}
}
GetDlgItemText(IDC_USER,user);
GetDlgItemText(IDC_PASS,pass);
if(mysql_query(myDB,"select * from login"))
res=mysql_store_result(myDB);
row = mysql_fetch_row(res);
MessageBox(row[0]);
exit_here:
mysql_close( myDB);
please sir help me to solve this one
thanks again
hi
|
|
|
|
|
No problem, does the debugger indicate which line might be cusing the access violation ?
Try changing the code a little as your error handling could be improved, I rewrote it like this, but obviously have not tested it, so give it a go and see if that improves anything.
int i;
MYSQL *myDB = NULL;
MYSQL_RES *res = NULL;
MYSQL_ROW row;
CString user,pass,aqp;
if((myDB = mysql_init((MYSQL*) 0)) &&
mysql_real_connect(myDB,"localhost","root",NULL,NULL,3306,NULL,NULL))
{
if(mysql_select_db( myDB,"gourav"))
{
GetDlgItemText(IDC_USER,user);
GetDlgItemText(IDC_PASS,pass);
if(mysql_query(myDB,"select * from login"))
{
res=mysql_store_result(myDB);
row = mysql_fetch_row(res);
MessageBox(row[0]);
}
}
else
MessageBox("Can't connect !\nPlease try later.") ;
mysql_close(myDB);
}
regards,
|
|
|
|
|
thanks sir
sir i try this one but it does not work
as same error at line
row = mysql_fetch_row(res);
before this same error at same line
thanks
hi
|
|
|
|
|
What is the value of 'res' when this line is executed, you'll need to strp through the code in your debugger.
res=mysql_store_result(myDB);
|
|
|
|
|
sir after debugging :
myDB shows this value 0x00ba4008
and res shows this 0x00000000
thanks.
hi
|
|
|
|
|
I suspect the call is failing, have you tried adding mysql_error() to see if you get an error.
Also, change this part of the code:
if(mysql_query(myDB,"select * from login"))
{
res=mysql_store_result(myDB);
row = mysql_fetch_row(res);
MessageBox(row[0]);
}
to this:
<pre
if(mysql_query(mydb,"select *="" from="" login"))
{
="" res="mysql_store_result(myDB);
" if(res)
="" {
="" row="mysql_fetch_row(res);
" if(row="" !="FALSE)
" messagebox(row[0]);
="" }
}<="" pre="">
|
|
|
|
|
yes sir i think u r right call is failing
becauze when debugger comes on if(res) it will show login window again
and this will stop debugger
but i dont know sir why this if(mysql_query(myDB,"select * from login"))
is not fetching result
[sir i use mysql 6.0 and VC++ 6.0(is there any problem Sir)]
hi
|
|
|
|
|
Are there any records in the database table ?
|
|
|
|
|
yes sir
i have database gourav , a table login and
this table has three fields user , password and id
and there are three records in this table
hi
|
|
|
|
|
What is the return value from the mysql_query(myDB,"select * from login")) function ?
Change it to this for a test:
int i = mysql_query(myDB,"select * from login");
What is the value of i ?
|
|
|
|
|
sir return value for
int i = mysql_query(myDB,"select * from login");
and i shows value 1 when use debugger
hi
|
|
|
|
|
Add the try/catch block that Shouvik suggested, it should help diagnose the problem.
|
|
|
|
|
thanks a lot sir
u have devoted a lot of time for me
thanks a lot
hi
|
|
|
|
|
No problem, just trying to help a fellow coder.
|
|
|
|
|
Surround the code for retrieving with a try and catch. then get the error reason by catching the Exception object throught the method what();
I think Jonathan is right. The recordset value is NULL and hence throws an Acess Violation Error
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing.
Oscar Wilde (1854-1900)
Regards...
Shouvik
|
|
|
|
|
sir thnaks
but i dont know about the what(); function
so can u help me sir
thanks
hi
|
|
|
|
|
Actually I'm not well versed with ODBC section in VC 6.0 So I m just givin u a generalized concept.
Whenever you surround any code with try catch you throw an exception which is the Object of CException Class.
try
{
}
catch(CException e)
{
MessageBox(e.what());
}
So this way you can atleast trace what error are u getting.
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing.
Oscar Wilde (1854-1900)
Regards...
Shouvik
|
|
|
|
|
sir what() is not working with this
it will give error
'what' : is not a member of 'CException'
please sir solve this
thanks
hi
|
|
|
|
|
Change the code to this:
int i;
MYSQL *myDB = NULL;
MYSQL_RES *res = NULL;
MYSQL_ROW row;
CString user,pass,aqp;
try
{
if((myDB = mysql_init((MYSQL*) 0)) &&
mysql_real_connect(myDB,"localhost","root",NULL,NULL,3306,NULL,NULL))
{
if(mysql_select_db( myDB,"gourav"))
{
GetDlgItemText(IDC_USER,user);
GetDlgItemText(IDC_PASS,pass);
if(mysql_query(myDB,"select * from login"))
{
res=mysql_store_result(myDB);
if(res)
{
row = mysql_fetch_row(res);
if(row != FALSE)
MessageBox(row[0]);
}
}
}
else
MessageBox("Can't connect !\nPlease try later.") ;
mysql_close(myDB);
}
catch(CException& e)
{
MessageBox(e.what());
}
do you get a messagebox with a description of the error in it ?
|
|
|
|
|
no messagebox sir
because what() is not working with this
it will give error
'what' : is not a member of 'CException'
thanks
hi
|
|
|
|
|
Change what() to ReportError()
|
|
|
|