Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
mysql cmds
SQL
mysql> CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';//created.

mysql> create database mydat;//created
mysql> USE mydat; /database changed;
mysql>create table mytb(one int, two int); //created
mysql> insert into mytb(one , two )VALUE (10, 15);
mysql> select * from mytb;
+------+------+
| one  | two  |
+------+------+
|   10 |   15 |
|   10 |   15 |
|   10 |   15 |
+------+------+

so datase is done.
now i am begining conection in c#
first of all i have using MySql.Data.MySqlClient; and referense mysql.data
and my code is
  using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Full_Apl_Of_Storage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
                        string MyConString=("SERVER=localhost;DATABASE=mydb;UID=myuser;PASSWORD=mypass;");

			MySqlConnection connection = new MySqlConnection(MyConString);
			MySqlCommand command = connection.CreateCommand();
			MySqlDataReader Reader;
			command.CommandText = "select * from mytb;";
			connection.Open();
			Reader = command.ExecuteReader();
			while (Reader.Read())
			{
				string thisrow = "";
				for (int i= 0;i<Reader.FieldCount;i++)
						thisrow+=Reader.GetValue(i).ToString() + ",";
				listBox1.Items.Add(thisrow);
			}
			connection.Close();
		}
        }

            
    
}


but there is eror : access denied for 'user'@'localhost'
to dataabase my db


please help me and edvise somethig...
Posted
Updated 19-Mar-12 4:39am
v2
Comments
Rajesh Anuhya 19-Mar-12 10:40am    
Edited
--RA
Sergey Alexandrovich Kryukov 19-Mar-12 18:00pm    
Please don't posting non-answers using "Add your solution here".
--SA

First of all, make sure the database settings in your db-config.php are correct, specifically the name and password of your MySQL user, the name of your database, and the name of your MySQL server.

If you're running your own server, you may need to give your MySQL user proper permissions. Log in to MySQL as the MySQL root user and issue these commands:

GRANT ALL PRIVILEGES ON database_name TO user@host IDENTIFIED BY 'password';
FLUSH PRIVILEGES;


Replacing the lower-case strings with the actual values, of course.
 
Share this answer
 
v2
Simple. You created the database as "mydat" and trying to connect to it as "mydb"
 
Share this answer
 
Comments
tmchedlishvili 19-Mar-12 11:13am    
yes i find this one but still is same problem...
oh oh i try on somethings but...unfortunately
result is not good
(GRANT ALL PRIVILEGES ON mydat TO user@host IDENTIFIED BY 'mypass';
FLUSH PRIVILEGES; )
 
Share this answer
 
v2

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