MySQL .NET Connector Error Code 1142

I was trying to execute an INSERT command from my .net application.  However I got the following error.  

Error Message: INSERT command denied to user 'user_id'@'my_ip' for table 'table_name'
Error Code: 1142

I've used the following commands to create the user and grant the privileges.
CREATE USER 'user_id'@'%' IDENTIFIED BY 'password';
GRANT INSERT ON [Database_Name].[Table_Name] TO 'user_id'@'%';
FLUSH PRIVILEGES;

Open in new window


Also I can use MySQL Workbench on the same machine to execute the INSERT command.  Please help.  Thanks.
thomaszhwangAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pratima PharandeCommented:
try

GRANT INSERT ON 'db'.'tablename' TO 'username'@'localhost'

refer
http://stackoverflow.com/questions/5698981/insert-command-denied-in-mysql
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thomaszhwangAuthor Commented:
Thanks for your reply, but it doesn't work - same error message.
0
Pratima PharandeCommented:
http://osdir.com/ml/db.mysql.bugs/2002-10/msg00248.html

When a grant is issued on a specifc table for a given user, specifically an
INSERT or UPDATE, the named user will not be able to use that granted
ability if the named table is specified in the grant statement with
uppercase characters.

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

thomaszhwangAuthor Commented:
But my table was defined in upper case.  How can I grant the privilege then?

Also I was able to do INSERT in MySQL Workbench.  How to explain this?

Thanks.
0
gnoonCommented:
are both mysql workbench and .net app running on the same domain?
what domain you are using in the connection string of .net?
use

show grants for 'user_id'@'%';
show grants for 'user_id'@'localhost';

command to check for privileges on [Database_Name].[Table_Name].
how about drop other domains of 'user_id' to remain only '%'?
are you using hosts file?
0
thomaszhwangAuthor Commented:
are both mysql workbench and .net app running on the same domain?
Yes.

what domain you are using in the connection string of .net?
I didn't specify a domain in my connection string.  Should I?  What domain should I specify?

use

show grants for 'user_id'@'%';
show grants for 'user_id'@'localhost';

command to check for privileges on [Database_Name].[Table_Name].

how about drop other domains of 'user_id' to remain only '%'?
Will check later

are you using hosts file?
No
0
gnoonCommented:
.NET Connector uses connection string to connect MySQL and MySQL provides rights for the user/domain specified in the connection string. For example,

Server=localhost;Database=myDataBase;Uid=user_id;Pwd=password;
rights of 'user_id'@'localhost' shall be use for access over named pipe on Windows

Server=127.0.0.1;Database=myDataBase;Uid=user_id;Pwd=password; // specific actual IP or domain of MySQL server
rights of 'user_id'@'%' or other matching user/domain shall be use for access over TCP/IP

You must grant privileges to the right user, or for testing just make it exists only '%'.
0
thomaszhwangAuthor Commented:
I used the following code to grant the privilege.
GRANT INSERT ON [Database_Name].[Table_Name] TO 'user_id'@'%';

Open in new window


As you can see, I have already used '%'.  Is this what you meant?

Btw, I use the IP of the MySQL server in my connection string.
0
gnoonCommented:
Hmmm It seems MySQL does not use it. Maybe there is a user which has a host which more specifically matches your host, i.e. a blank username with '%', then it will use that instead.
0
thomaszhwangAuthor Commented:
Is there a way I can check this?
0
gnoonCommented:
Execute the following SQL statement on the mysql database

SELECT * FROM user WHERE user='';

This table will contains all MySQL's users and their privileges. If found, you can delete the blank user

DELETE FROM user WHERE user='' and host='%';

then finally

FLUSH PRIVILEGES;
0
thomaszhwangAuthor Commented:
Thanks, but
SELECT * FROM user WHERE user='';

Open in new window

returns Empty Set.
0
gnoonCommented:
So, how many records by following command

SELECT * FROM user WHERE user='user_id';
0
thomaszhwangAuthor Commented:
There two rows.  One is @'%'.  The other is @'localhost'.
0
gnoonCommented:
OK. Now we knows that one of them have INSERT privilege (workbench can do that) and the other does not have but we doesn't know which one is chosen during accessing from .NET Connector.

To check this, please execute the following SQL statement on both workbench and .NET Connector and compare the results

SELECT USER(), CURRENT_USER();

Open in new window


It would return a record and please post it here, if possible.

USER() returns the username you specified and the client host from which you connected and CURRENT_USER() returns the username and hostname values from the User and Host columns of the user table record the server used to authenticate you.
0
thomaszhwangAuthor Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.