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.

7
  • Why do you think there's a difference between connecting to MySQL in ASP.NET and console application>? Commented Aug 16, 2012 at 9:46
  • not sure if this will work with EF5.0... stackoverflow.com/questions/76488/… Commented Aug 16, 2012 at 9: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. Commented Aug 16, 2012 at 9: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. Commented Aug 16, 2012 at 9:52
  • well i was thinking the 2nd answer pointing to 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 Commented Aug 16, 2012 at 10:01

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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";
}

1 Comment

Not a trick, its one of the ways EF wants you to do things. I simply provided code that would work with your current code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.