|
-
May 16th, 2012, 06:58 AM
#1
MySQL and C#
I have problem that I cannot reach my data bases trought my c# project.
Im using latest versions of .Net and MicrosoftVisual C# 2010 Express, XAMPP for apache and MySql, connector from the MySQL folder. The program says Unknown database "name". I have made this database in phpmyadmin panel and c it working just cant reach it. Please help me. There is the cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace bazaffs
{
class Program
{
static void Main(string[] args)
{
try
{
MySqlConnection conn = new MySqlConnection("Server=127.0.0.1;Port=3306;Database=aaa;Uid=root;Pwd=root;");
conn.Open();
MySqlCommand command = conn.CreateCommand();
command.CommandText = "Select * from bbb ";
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader.ToString());
}
Console.ReadLine();
conn.Close();
}
catch (Exception ex)
{
Console.Write(ex.Message.ToString());
Console.ReadLine();
}
}
}
}
-
May 16th, 2012, 07:42 AM
#2
Re: MySQL and C#
Your Code looks correct. I would think you need to get MySQL setup properly.
Always start with the basics.
1. Download and install MySQL Workbench, from the MySQL.com site.
2. Setup a local connection, using 127.0.0.1, using the root username
3. Try to Open a new Query window.
a. Can you open and connect?
b. Do you see the 'aaa' database?
If not, your code will not work and you will need to get MySQL setup properly. If you need help with that, You can probably find step by step instructions on the MySQL web site, and their forums.
-
May 16th, 2012, 09:14 AM
#3
Re: MySQL and C#
Well I have never used MySQL workbenth before so I have no idea how to use it. This is the reason I decided to use phpmyadmin to edit databases. I used mysqladmin prompt to be sure that mysql is started and its running on my machine so its fine and I still cannot connect
-
May 16th, 2012, 10:41 AM
#4
Re: MySQL and C#
Even though MySQL is running fine and you can connect from mysqladmin, that does not mean it is setup for connections coming from the network (127.0.0.1). So, you will probably have to configure mysql in a couple of ways.
1. Allow the server to listen for connections on the network. Network connections are usually disable by --skip-networking in the config file.
2. Allow access to a user to connect from the network.
GRANT ALL PRIVILEGES ON *.* TO root@'127.0.0.1' IDENTIFIED BY 'pwd';
FLUSH PRIVILEGES;
If MySQL is not setup, you will not be able to connect. If you can get the MySQL workbench to connect, the .NET connections will work fine.
-
May 16th, 2012, 11:54 AM
#5
Re: MySQL and C#
Well I made connection using this guide http://forums.hawkhost.com/topic/109...l-development/
And than i got 3 databases that are not mine. If i use some of this bases my c# project connects and fetches the results, but the datebases that I made on phpmyadmin panel are not there. Is there some way to add those databases to this workbentch ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|