If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Errors connecting to MySQL 4.0.15

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-28-04, 02:30
TheOne0822 TheOne0822 is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
Errors connecting to MySQL 4.0.15

//1. I'm trying to connect to MySQL 4.0.15 using Visual C++ 6.0. This is the sample code that I'm using. I'm just simply trying to connect and query the database:


#include<iostream.h>
#include<winsock.h>
#include<mysql.h>
#include<windows.h>
#include<stdio.h>




#define host "C:\mysql\bin\mysql.exe"
#define user "Enrique0822"
#define password "xxxxx"
#define database "Numberlyzer"

MYSQL *conn;//pointer to active database



int main()
{

conn = mysql_init(NULL);

mysql_real_connect(conn,host,user,password,databas e,0,NULL,0);//connects you to the database.

MYSQL_RES *result;//varible to return a result
MYSQL_ROW row;//variable to return row
unsigned int i;//variable to increment in the loop in case more than one row is returned
unsigned int n;

mysql_query(conn,"SELECT * FROM pic3");//query the database

result = mysql_store_result(conn);//store result in the result variable

n = mysql_num_rows(result);//variable that will allow you to loop through the number of rows returned

while ((row = mysql_fetch_row(result)) != NULL)
{

for (i=0; i<mysql_num_fields(result); i++)
{

printf("%s\n",row[i] != NULL ? row[i] : "NULL");
}
}
mysql_close(conn);

return 0;

}


//2. I also double checked to make sure that I included the mysql++.lib file under project settings link tab. Maybe someone has a better set of eyes than I do but the code looks good to me. When I try to compile I get the following 3 errors:

--------------------Configuration: database - Win32 Debug--------------------
Compiling...
database.cpp
c:\mysql\database\database.cpp(25) : warning C4129: 'm' : unrecognized character escape sequence
c:\mysql\database\database.cpp(25) : warning C4129: 'm' : unrecognized character escape sequence
c:\mysql\database\database.cpp(36) : warning C4244: '=' : conversion from 'unsigned __int64' to 'unsigned int', possible loss of data

database.obj - 0 error(s), 3 warning(s)


//3. The program allows me to link inspite of these warnings. But when I attempt to run the program, it simply crashes. When this happens I try to debug the error and a popup window in the debugger generates the following message:

Unhandled exception in database.exe (LIBMYSQL.DLL) : 0x0000005: Access Violation


//4. I'm not sure if this part is relevant but after I click ok on the popup windows message, I see the following messages displayed under the debug window tab:

Loaded symbols for 'C:\mysql\Database\Debug\database.exe'
Loaded 'C:\WINDOWS\system32\ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\libmySQL.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wsock32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ws2_32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ws2help.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\mswsock.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\dnsapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\winrnr.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wldap32.dll', no matching symbolic information found.
Loaded 'C:\Program Files\NewDotNet\newdotnet4_88.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ole32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\oleaut32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wininet.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\SHLWAPI.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\crypt32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msasn1.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\imm32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\lpk.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\usp10.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.10.0_x-ww_f7fb5805\comctl32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rasadhlp.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\comctl32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wshtcpip.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\version.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\apphelp.dll', no matching symbolic information found.
The thread 0x9A0 has exited with code 0 (0x0).


//5. In case anyone is wondering I'm using Windows XP and I downloaded the MySql++ API version 1.7.1. Any help would be greatly appreciated. I'm pretty good with SQL and C++ programming but I just can't seem to get them to work together:-(
Reply With Quote
  #2 (permalink)  
Old 01-28-04, 22:53
stacey_richards stacey_richards is offline
Registered User
 
Join Date: Aug 2003
Posts: 32
Do you have to escape back slashes?

#define host "C:\\mysql\\bin\\mysql.exe"
Reply With Quote
  #3 (permalink)  
Old 01-29-04, 01:22
TheOne0822 TheOne0822 is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
Quote:
Originally posted by stacey_richards
Do you have to escape back slashes?

#define host "C:\\mysql\\bin\\mysql.exe"

No, but I gave it a try anyway....didn't work though. Thanks for the help.

-TheOne0822-
Reply With Quote
  #4 (permalink)  
Old 01-29-04, 09:31
vanekl vanekl is offline
Registered User
 
Join Date: Nov 2003
Posts: 91
1. Actually, you aren't using the C++ api, you are using the C api.
That's probably why you are having linking warnings.
I think you should probably be linking to libmySQL.dll
(or libmysqlclient.a if you compiled the library yourself).

//*****************************
You're host is wrong.
'host' may be an IP address, NULL, or "localhost", but not the name of an executable program.
//*****************************

2. Warnings will not cause a link to fail.

3. You aren't checking the return values of mysql_init or mysql_real_connect for errors.
You are getting an error and instead of aborting you are querying the database with a
bad conn pointer. (I think it has been set to 5, which is definately a bad pointer.)

conn = mysql_init(NULL); /* allocate, initialize connection handler */
if (conn == NULL) {
... error ...
return (NULL);
}

void *a = mysql_real_connect (conn, host_name, user_name, password,
db_name, port_num, socket_name, flags);
if ( a == NULL ) {
... error ...
return (NULL);
}


4. No symbolic information means those dlls were not compiled with the debug option,
so you can't see any debugging information from those dlls.

5. You should probably download the C API instead.

This is an example of using the C++ API:
http://www.mysql.com/documentation/m..._Tutorial.html

Don't worry, you can still use the C API from a C++ program. I do all the time,
except instead of using Visual C++ I use gcc. I wouldn't recommend using gcc,
however, because if you do you also have to recompile the libmysqlclient library
with gcc. MySQL has already compiled it using Visual C++ so it makes sense to use
Visual C++ whenever you can.
Reply With Quote
  #5 (permalink)  
Old 01-29-04, 18:16
TheOne0822 TheOne0822 is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
Thanks to everyone that responded, I really appreciate it. I revamped the code a little. I also realized that I hadn't correctly set my passwords. Duh!! I also had to make sure that I linked the mysql++.lib, mysqlclient.lib, and libmySQL.lib to the project.

#include<winsock.h>
#include<stdio.h>
#include<mysql.h>



int main()
{
MYSQL_RES *result;//varible to return a result
MYSQL_ROW row;//variable to return row



/*a is the connection to the database*/
MYSQL *a, mysql;
int query_error;


/* initialize and open the connection */
mysql_init(&mysql);
a = mysql_real_connect(&mysql,"1XX.X.X.X","root","XXXX XX","Numberlyzer", 0, 0, 0);


/* if the connection failed, then display the error and exit. */
if (a == NULL)
{
printf(mysql_error(&mysql));
return 1;
}

/*query the database*/
query_error = mysql_query(a,"SELECT date,numbers FROM pic3");


/* if the query error is not 0 (no error), display the error and exit */
if (query_error != 0)
{
printf(mysql_error(a));
return 1;
}

/* Return a query result */
result = mysql_store_result(a);



/* Loop through and display each row in the query result */
while (( row = mysql_fetch_row(result)) != NULL )
{
printf("Date: %s Numbers: %s\n",(row[0] ? row [0] : "NULL"),(row[1] ? row[1] : "NULL"));
}


/* free the resources associated with the query result */
mysql_free_result(result);



/* close the connection */
mysql_close(a);

return 0;

}
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On