4

I tried to connect to the mysql server via remote connection.

The connection string is server={IP};database={DB};uid={usernname};pwd={password};

        try {
            conn.Open();
            sqlCmd = conn.CreateCommand();
            sqlCmd.CommandText = sqlStr;
            reader = sqlCmd.ExecuteReader(); //->LINE 32
            while(reader.Read()) //Add to library
        } catch (Exception ex) { }
        finally {
           //Close connection and reader
        }

and i got this error.

08 June 2015 12:58:46 PM   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
   at ProgramTest.Program.Main() in C:\Projects\ProgramTest\ProgramTest\Program.cs:line 32

I tried to connect using Mysql Workbench and success receiving results.

any code i missed that cause the problem?

thanks in advance!

user2936719
  • 165
  • 2
  • 10
  • Are you share a connection object with multiple command objects? – Saravana Kumar Jun 08 '15 at 05:17
  • No.. i run this code in the program function in program.cs before everything else executed to make sure no other connection established. – user2936719 Jun 08 '15 at 05:21
  • debug and show the error message. – Saravana Kumar Jun 08 '15 at 05:25
  • String sqlStr = "SELECT * FROM USERS WHERE Username=@username AND Password=@password AND isActive=1"; some param in the command section sqlCmd.Parameters.AddWithValue("@username", "1"); sqlCmd.Parameters.AddWithValue("@password", "1"); – user2936719 Jun 08 '15 at 05:32
  • 1
    `MySqlClient expects ? parameter char instead of @.` Check this http://stackoverflow.com/questions/14687258/mysql-data-mysqlclient-mysqlexception-0x80004005. – Saravana Kumar Jun 08 '15 at 05:34
  • Not a problem. I have changed '@' -> '?' e.g. @username -> ?username. But doesnt help. Still same error. on the question above. And '@' doesnt effect on local access. Very confusing.. – user2936719 Jun 08 '15 at 05:56
  • Maybe there is a firewall setting in the way, or your mysql server does not allow remote connections. check your settings. – Timothy Groote Jun 08 '15 at 06:35
  • I dont think thats its a firewall/connection problem. Same settings on the connection string set in the mysqlworkbench, but mysqlwb can retrieve the data. – user2936719 Jun 08 '15 at 06:40
  • What is the type of sqlCmd? You can use "MySqlCommand" if you didn't use it. You can refer to [this link](http://stackoverflow.com/questions/652978/parameterized-query-for-mysql-with-c-sharp) – Heinz Siahaan Jun 08 '15 at 07:57
  • MySqlConnection conn = new MySqlConnection(ConnStr); MySqlCommand sqlCmd; MySqlDataReader reader = null; My other code before the try - catch. It should be like that right? – user2936719 Jun 08 '15 at 09:20
  • @user2936719 : Did you got a solution to your problem? I am also having the same issue, not sure where is the error? :( Can you share if you have your problem resolved? – Ianthe Aug 01 '16 at 08:58
  • @Ianthe my problem is about the access allowed by MySql. The problem above i tried accessing it through LAN. I need to recreate the mysql user. – user2936719 Aug 01 '16 at 09:01
  • @user2936719 Thank you for your comment, but my MySql database is in the localhost, so it should not be a problem. Do you know what maybe the cause of my issue? – Ianthe Aug 01 '16 at 09:05

1 Answers1

0

This question was active before 5 years. i am not sure it will help you as of now. But the same issue i also faced from last two days. The reason for the issue is "your passing huge value for the parameter beyond it's limit."

Example : the parameter 'name varchar(15)' and your passing value for the name xxxyyyxxx.....xxx which is more than 15. try to increase the varchar limit from 15 to 100 and then try. it will work i hope. that's the same worked for me too.