MySQL Connector, asynchronous connections.

mrnugger

Member
Joined
Aug 20, 2006
Messages
6
Ive been trying to make asynchronous connections, everything runs smoothly up to the EndExecuteReader(), it isnt returning any results.

Before you take a look at the code, any documentation on .NET connector and using these asynchronous function would be appreciated, Ive found ZERO documentation on asynchronous MySQL methods using C# and the provided connector.

Here is the code of the method Im trying to write:

Code:
public int getLogin(string name, string password)
{
MySqlConnection connection = new MySqlConnection(connectionString);
MySqlCommand command = new MySqlCommand("select * from players where name = " + name
+ " and password = " + password + "");
connection.Open();
MySqlDataReader reader = null;

IAsyncResult result = command.BeginExecuteReader();
while(!result.IsCompleted)
{
// while it isnt completed, wait.
}
if (result.IsCompleted)
{
reader = command.EndExecuteReader(result);
}

return 0;
}
It returns Object is null exception on the variable reader. It seems the line "command.EndExecuteReader(result);" isnt returning anything.
 
If you step through the code are you seeing anything returned from the command.EndExecuteReader(result) statement?

Have you tried executing the command as a synchronous call just to check it is returning a value correctly?

In fact it looks like you could have an error with your command syntax try
C#:
MySqlCommand command = new MySqlCommand("select * from players where name = " + name
+ " and password = " + password + "");
as you seem to be missing a character after then name is being concatenated.
 
Tried it, no luck :\, reader is still giving a null reference exception. I switched the whole code to synchronous and it worked, but I need async. for my program .

Does anyone know or have ANY documentation / examples on asynchronous usage of the .NET MySQL Connector? I found NONE (this is really a bummer).
I tried using MSDNs System.Data.Sql asynchronous examples but it seems they wont work when using MySQL.Data.
Do you know if its possible to connect to a MySQL server using .NET Sql.Data commands?
 
Have you got the most recent version of the MySQL .net library? Only guessing but it might not be supported in all versions...

Failing that you could always wrap the execute reader call in a async delegate call... I can knock up a quick example if you need me to.
 
Fixed it, the problem was I used the only documentation I found which was related, and it used Sql.Data library, so there was a minor difference in the Connector declaration which I failed to notice... thanks anways :)!
 
Back
Top