Reputation: 13865
I am trying to connect to a remote MySQL database using Visual C# 2008 Express Edition. Is there a way to connect using the editor, or do I have to code the connection manually? The editor has a clear and easy-to-follow wizard for connecting to Microsoft SQL Server and Access databases, but I don't see an easy way to add a remote MySQL datasource. I tried searching the help, but couldn't find anything useful.
Has anyone done this using the editor? Or can point me in a useful direction?
Upvotes: 3
Views: 27721
Reputation: 5941
now u can use entity to mysql http://www.codeproject.com/Tips/426790/Using-MySQL-with-Entity-Framework
Upvotes: 0
Reputation:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome ...!");
String conString = "SERVER = localhost; DATABASE = l2emu; User ID = root; PASSWORD = password;";
MySqlConnection connection = new MySqlConnection(conString);
String command = "SELECT * FROM characters";
MySqlCommand cmd = new MySqlCommand(command,connection);
MySqlDataReader reader;
try
{
connection.Open();
cmd.ExecuteNonQuery();
reader = cmd.ExecuteReader();
cmd.CommandType = System.Data.CommandType.Text;
while (reader.Read() != false)
{
Console.WriteLine(reader["char_name"]);
Console.WriteLine(reader["level"]);
}
Console.ReadLine();
}
catch (MySqlException MySqlError)
{
Console.WriteLine(MySqlError.Message);
}
}
}
}
here is the example but you must download the mysql connector,
Upvotes: 0
Reputation: 29899
EDIT: I didn't check Rishi Agarwal's answer before posting. I think his answer has more insight on the express edition
I am not sure about this and express edition, but you should try MySQL Connector/Net. It works fine with my VS2008 Pro.
Upvotes: 1
Reputation: 1185
You will have to code the connection manually to connect to a remote MySQL database using Visual C# 2008 Express Edition.
VS 2008 Express (and VS 2005 Express too) doesn't allow you to use MySQL .Net Provider through the Data Source Dialog. The non-Express edition allow you to do the same.
To use MySQL in VS Express, you will have to include a reference to the MySQL DLLs. If you have installed the MySQL .Net Provider, the DLLs will be in C:\Program Files\MySQL\MySQL Connector Net x.x.x). Or copy the DLLs to the Bin folder of your project. After including the DLLs, you can make a ConnectionString to connect to the remote MySQL Database.
The MySQL .Net Provider can be found here
A similar question was asked in thread 396593 here
Upvotes: 8
Reputation: 1064224
The good thing about "express" (or even just "csc") is that even if it doesn't have a designer to help with some things (like setting up the connection string to most useful databases), the core framework is not limited. So you'll probably have to put in the connection string yourself and add a reference to the MySQL/.NET provider, but it should work at runtime, even in debug.
Which is very nice ;-p
Upvotes: 0