0

I am creating an application which uses databases extensively. Now we are using Mysql connector, plain sql syntax to make our needs. Now we are trying to employ LINQ for the database queries. So I am trying to implement the DBcontext. But it is not connecting properly. The problem is in connection string.

This is the method I am using now,

class My_DB_Context: DB_Context
{
     public My_DB_Context(string connection_String):base(connection_String){}
     void make_Some_Transaction(){}
}

public void Main()
{
     string conn_Str = "SERVER=localhost;DATABASE=my_DB;UID=temp_User;PASSWORD=password;";

     My_DB_Context temp = new My_DB_Context();
     temp.make_Some_Transaction();
}

Can anybody say how to achieve this?. There are numerous post about how to achieve this in ASP.Net . But, I couln't find one for console like application. This article promises that this is possible.

Note: I am using C#/.Net 4.0. Visual Studio 2010, Entity Framework 5.0.0

EDIT-1: I forgot to mention that I know nothing in ASP.Net . So , I can't understand the parameters they changed in that article. These are exception messages I am getting

An error occurred while getting provider information from the database. This can be 
caused by Entity Framework using an incorrect connection string. Check the inner 
exceptions for details and ensure that the connection string is correct. 

Below is the inner exception

A network-related or instance-specific error occurred while establishing a connection 
to SQL Server. The server was not found or was not accessible. Verify that the 
instance name is correct and that SQL Server is configured to allow remote connections"

EDIT-2: After Ingo's comment, now only I noticed that they released it on yesterday only. But, this issue is very basic . They wont change these kind of things easily. So, answers for old Entity FrameWorks also welcomed by betting on compatibility.

EDIT-3: I saw something called as entity_Connection_String. I think this is the thing I have to dig.

Community
  • 1
  • 1
prabhakaran
  • 5,126
  • 17
  • 71
  • 107
  • Why do you think there's a difference between connecting to MySQL in ASP.NET and console application>? – Karel Frajták Aug 16 '12 at 09:46
  • not sure if this will work with EF5.0... http://stackoverflow.com/questions/76488/using-mysql-with-entity-framework – Ingo Aug 16 '12 at 09:47
  • Connecting to database should be independent on the of the application you are using, so you can use plain EF, NHibernate or plain SQL commands in ASP.NET app, console app, Winforms app, Windows service, etc. I also don't know what parameters are you talking about. – Karel Frajták Aug 16 '12 at 09:52
  • @Ingo I refereed that already . I changed the connection string with no avail. I tried to add the "provider", and got the reply along the lines of "provider" is not in syntax. – prabhakaran Aug 16 '12 at 09:52
  • well i was thinking the 2nd answer pointing to http://pattersonc.com/blog/2009/04/ might be interesting. As that is an older post, it is of course possible that the solution won't work with EF 5.0 which is brandnew and ... is it even officially released? ... i think still in beta.... OHHH it has been released... yesterday – Ingo Aug 16 '12 at 10:01
  • @Ingo http://nuget.org/packages/EntityFramework – prabhakaran Aug 16 '12 at 10:04
  • @Karel You are right. It seems I am missing some small piece. But, I can't figure it out. Please see the edit. – prabhakaran Aug 16 '12 at 10:12

2 Answers2

0

Entity Framework does work with MySQL. You will need to do the following:

  1. Include the MySql provided in your app.config
  2. Change your Main function to look more like this

Code:

public void Main()
{
   string conn_Str = "name=MyDbContextConnectionStringNameFromAppConfigFile";
}
Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
Kristofer Hoch
  • 246
  • 1
  • 7
0

You told us that you have the official mysql connector installed for .net, so that's a good thing

now your connection string has an error:

Yours:

SERVER=localhost;DATABASE=my_DB;UID=temp_User;PASSWORD=password

Should be:

Server=localhost;Database=my_DB;Uid=temp_User;Pwd=password;

source: http://www.connectionstrings.com/mysql#p28

JP Hellemons
  • 5,977
  • 11
  • 63
  • 128
  • Some more info http://stackoverflow.com/questions/3283820/using-mysql-with-entity-framework-4-and-the-code-first-development-ctp – JP Hellemons Aug 16 '12 at 13:50