mrnugger Posted March 28, 2008 Posted March 28, 2008 I've 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, I've found ZERO documentation on asynchronous MySQL methods using C# and the provided connector. Here is the code of the method I'm trying to write: 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 isn't 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);" isn't returning anything. Quote
Administrators PlausiblyDamp Posted March 28, 2008 Administrators Posted March 28, 2008 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 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mrnugger Posted March 28, 2008 Author Posted March 28, 2008 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 MSDN's System.Data.Sql asynchronous examples but it seems they wont work when using MySQL.Data. Do you know if it's possible to connect to a MySQL server using .NET Sql.Data commands? Quote
Administrators PlausiblyDamp Posted March 29, 2008 Administrators Posted March 29, 2008 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mrnugger Posted March 31, 2008 Author Posted March 31, 2008 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 :)! Quote
seanhogg Posted March 29, 2011 Posted March 29, 2011 hi <mrnugger>, Can you post the sample code which worked for you? Thanks. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.