Problem opening a DB.
Every time that I run my program and click on Submit Data, it gives me the below error message:
An error has occured while trying to open the database:
#28000Access denied for user ''@'localhost' (using password: YES)
MySQL is installed on the PC -- as a server -- that I'm developing and I have installed the connector and that works fine. Why is this happening?
# 1 Re: Problem opening a DB.
You are getting this error because you are not supplying a user to log into the database. Try this.
1. Open a commandline. Then start the MySQL client. You might have to change to the directory where the mysql binary files are. C:\Program Files\MySQL\MySQL Server 5.0\bin Type in "mysql -p" then enter foo for your password. You will probably get the same error message.
2. Type in "mysql" This will probably take you into the Client.
3. type "GRANT ALL PRIVILEGES ON testdb.* to 'genuser'@'%' indetified by 'foo';
4. type "GRANT ALL PRIVILEGES ON testdb.* to 'genuser'@'localhost' indetified by 'foo';
5. type "FLUSH PRIVILEGES"
6. Change you connection string to be...
conn.ConnectionString = "server=localhost;userid=genuser;password=foo;database=testdb"
or
conn.ConnectionString = "server=ipaddressofthelocalmachinegoeshere;userid=genuser;password=foo;database=testdb"
Then try your code again.
# 2 Re: Problem opening a DB.
You are getting this error because you are not supplying a user to log into the database. Try this.
1. Open a commandline. Then start the MySQL client. You might have to change to the directory where the mysql binary files are. C:\Program Files\MySQL\MySQL Server 5.0\bin Type in "mysql -p" then enter foo for your password. You will probably get the same error message.
2. Type in "mysql" This will probably take you into the Client.
When I get to this point, I get the below error.
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
Where did user ODBC come from? I don't get that. Also, when I start the MySQL client from the start menu, it seems to work fine, weird...
# 3 Re: Problem opening a DB.
It all has to do with how the server is initially installed. See, you need to be able to get into the server to set up the database. I probably should have explained a bit better.
By doing mysql -p from the command line, your are telling the client to load with no user but asking for the password. The error you are getting is normal. Step 1 I should have said is more of just a demonstration. Now try executing parts 2 through 6. You can open it from the Start Menu if you like.
MySQL is not like Access. It is more along the lines of SQL sever. You need a user to log in to the server. You can give this user any permissions you want. If you downloaded the Server, you should also have a docs folder. Check out the section on permissions. Or check out the documentation on the MySQL website.
But briefly...
You can create a user with the GRANT (see above) command. The FLUSH PRIVILEGES tells the server to reload the privileges table.
You can CREATE as many database as you would like. Use GRANT to give users permission to the database/tables.
For your users, you can specify where they are allowed to log in from. For example, lets say you have a service that resides on a particular machine, and uses let's say the PhoneCalls database. You main application is only allowed to read from the PhoneCalls database. You could do something like.
GRANT ALL PRIVILEGES ON PhoneCalls.* TO PCUpdate@'192.168.0.1' identified by 'foo';
GRANT SELECT ON PhoneCalls.* TO PCSelect@'%' identified by 'foo1';
FLUSH PRIVILEGES;
Now, the user PCUpdate can update ANY table in the PhoneCalls database but only from the computer with the 192.168.0.1 IP Address.
User PCSelect can only execute SELECT statements against the PhoneCalls database. However, it can issue that select from ANY computer.
Also, localhost is treated differently. Usually, the only user you really want to give permission to use from localhost is root/admin/whoever the DBAdmin is. Any usually, you will give them permissions to all the databases. That way they can Manage the Databases as necessary.
Hope this helps.
# 4 Re: Problem opening a DB.
GRANT ALL PRIVILEGES ON PhoneCalls.* TO PCUpdate@'192.168.0.1' identified by 'foo';
I got the below error when I tried this portion.
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the ight syntax to use near 'PRIVILIGES ON testdb. * TO name@'205.1.1.242' identified by 'foo'' at line 1
# 5 Re: Problem opening a DB.
With mysql, the first word is usually where the error is. In this case...
PRIVILIGES should be...
PRIVILEGES
# 6 Re: Problem opening a DB.
Thanks, the connection seems to be working now.
# 7 Re: Problem opening a DB.
No Problem.
I have lots of experience in VB 6/.net + Mysql . If you have more questions I should be around to help.
# 8 Re: Problem opening a DB.
I've decided to be lazy and make the connection as root :) . I've worked with queries and such extensively, but never had the need to touch the portion where you add and manage users.
# 9 Re: Problem opening a DB.
One more quick question. Recently I've worked on a project where I used Access as a DB. In this one and past projects I've used the DataGrid object (it's easy to display the plethora of records I have to go through.)
One thing that I've noticed is that once I query the database and populate the datagrid, in the current project -- the one with MySQL -- all of the records are shown instantly. However, in the previous project, I have to click on a button in order to expand the records and view all of them. I've compared the properties for both datagrid objects and found them to be the same (with the exception of a few negligible things such as TabIndex, Size, Position, etc.) With the exception of types of databases used -- MySQL as opposed to Access -- there is no difference between the information that is displayed in those datagrid objects that might cause one to have all of the records to be collapsed and the other to be expanded. Why is this happening? Is there some value/field/function that needs to be run in order for all of the values to expand instantly?
# 10 Re: Problem opening a DB.
I've decided to be lazy and make the connection as root :) . I've worked with queries and such extensively, but never had the need to touch the portion where you add and manage users.
Too funny. I don't blame you. Just be careful if you put this into production. Even if you start out small at some point you might want to start implementing user based permissions. And then when you deploy your app you might not remember to replace the connection string in your app. And as the voice of experience, it is not a fun thing when 100 people are telling you the application doesn't work anymore. :eek:
# 11 Re: Problem opening a DB.
One more quick question. Recently I've worked on a project where I used Access as a DB. In this one and past projects I've used the DataGrid object (it's easy to display the plethora of records I have to go through.)
One thing that I've noticed is that once I query the database and populate the datagrid, in the current project -- the one with MySQL -- all of the records are shown instantly. However, in the previous project, I have to click on a button in order to expand the records and view all of them. I've compared the properties for both datagrid objects and found them to be the same (with the exception of a few negligible things such as TabIndex, Size, Position, etc.) With the exception of types of databases used -- MySQL as opposed to Access -- there is no difference between the information that is displayed in those datagrid objects that might cause one to have all of the records to be collapsed and the other to be expanded. Why is this happening? Is there some value/field/function that needs to be run in order for all of the values to expand instantly?
Since I don't normally use a datagrid, I am not sure how the functionallity of it works. One thing I have noticed using Access/ODBC->MySQL, is that it seems to read 254 records at a time. It could be that Access is just not feeding you all the information while MySQL is.
# 12 Re: Problem opening a DB.
Too funny. I don't blame you. Just be careful if you put this into production. Even if you start out small at some point you might want to start implementing user based permissions. And then when you deploy your app you might not remember to replace the connection string in your app. And as the voice of experience, it is not a fun thing when 100 people are telling you the application doesn't work anymore. :eek:
I'm fully aware of the possible consequences of doing that. This app is supposed to run once in its lifetime. Infact, if it weren't for the fact that I figured out some new feature in VB .NET, I could easily delete this program after it's done without any consequence.