Click here to Skip to main content
15,900,512 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi

iam suffering a lot with connecting the mysql database to my windows application which was developed in C#.net , and i am trying to connect through the mysql dotnetconnector,

i had tried a lot ,i am getting the differtent types of errors so please try to help he, i had asked the same question before also but .....

i need some help that where i am going worng, please let me know

this is my sample code
<pre lang="cs"> 
MySqlConnection con = new MySqlConnection("server=192.168.0.89;database=test;uid=root;Pwd=dafd17512;");
           if (con.State.ToString() != "Open")
           {
               con.Open();
           }



when iam pinging i am getting the good result and more over in my browser i am opening and also creating the database from my browser only,
so i think i am going in the fine way but when i tried through the program line
i am getting the errors like
Host '22NDSTRE-F72BB9' is not allowed to connect to this MySQL server

here 22NDSTRE-F72BB9 is my system name , iam tring to communicate beetween the windows xp and windows7 and i also tried between windows xp- windowsxp
but no use so please give me a valiable suggestion

when i am trying to connect to localhost , its working perfectly
that sample code is


<pre lang="cs">
 MySqlConnection con = new MySqlConnection("database=test1;server=localhost;uid=root;");
              if (con.State.ToString() != "Open")
              {
                  con.Open();
              }




please give suggestion
Posted

Please check the following link for different options for connecting to MySQL database:

http://www.connectionstrings.com/mysql[^]
 
Share this answer
 
Comments
[no name] 29-Mar-11 6:58am    
i had tried a lot with this connecting strings
I guess this is a MySQL configuration issue. Per default MySQL only listens to 127.0.0.1 so you can connect only via localhost. Have a look at the my.cnf file and comment out the line stating 'bind 127.0.0.1'
 
Share this answer
 
You can try this[^]. Its a tutorial on how to bind your database server and your application server.

If it doesnt still solve your problem, you may try this[^]. Its a statement you will use to grant the user access to the database. Its questionable if your root account doesnt have access to your DB, but, it may be worth trying this as well. :)
 
Share this answer
 
Comments
Michel [mjbohn] 29-Mar-11 7:20am    
Even root may only connect from localhost if there isn't an entry in usertable to allow any host.
You can check this with "select User,Host from mysql.user where User='root';" If there no entry like '%' in the host column you can't do a remote login
walterhevedeich 29-Mar-11 7:34am    
I understand. That is why my statement was it is questionable if the root account does not have access to the DB. Anyway, I have provided another link for the configuration of his my.cnf, which was also similar to the solution you first posted. I should have read your post before giving mine. :)
hi i found the error after a lot of struggling



that is the changes in the MySQL server. just like giving the all privileges to the using user-id,and trying to keep the host as the "ANY" this is the particular you need to change


sample code:

MySqlConnection con = new MySqlConnection("server=192.168.0.89;database=test;uid=root;Pwd=dafd17512;");
           if (con.State.ToString() != "Open")
           {
               con.Open();
           }



and thanks for the support
 
Share this answer
 
Hi To all,

If you have mysql-workbench then login into it and go to admin panel and add the access entry over there.

For eg : root user from 192.168.1.1 is trying to access the database of 192.168.1.2
 
Share this answer
 
Comments
CHill60 15-Jul-13 14:32pm    
See the solutions that were added 2 years ago

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900