0

I'm facing an issue that I've never encoutered before using Entity Framemork with MySQL connector. I have the simple method core below:

ps_manufacturer manufacturer = null;
using (var context = new afflelou_storeEntities())
{
       var manufacturerList = context.ps_manufacturer.Where(m => m.id_AA_manufacturer == anId).ToList();
       if (manufacturerList.Count > 0)
       {
             manufacturer = manufacturerList.ElementAt(0);
       }
}
return manufacturer;

There is no data in database, so it should returns null. But instead, it throws me that error:

Open: underlying provider failed on Open

I've tried to use firstOrDefault but nothing works... I was thinking that it's a database connection error, but I'm always using a using from my database connexions, so it never happens to have a non closed connexion. Someone has already faced that issue ?

CodeNotFound
  • 22,153
  • 10
  • 68
  • 69
Hubert Solecki
  • 2,611
  • 5
  • 31
  • 63
  • 2
    StackOverflow is an English community, please rewrite your title in English. – ganchito55 May 17 '16 at 15:02
  • Looks like the error is rather in your connection string and has nothing to do with your provided code. Using the wrong provider perhaps (.i.e MySQL database but using SQL Client provider)? – LocEngineer May 17 '16 at 15:04
  • Possible duplicate of [MSSQL Error 'The underlying provider failed on Open'](http://stackoverflow.com/questions/2475008/mssql-error-the-underlying-provider-failed-on-open) – Nasreddine May 17 '16 at 15:04
  • @LocEngineer, a request is made just before on he same context and it works, so it doesn't come from the connexion string... – Hubert Solecki May 17 '16 at 15:11
  • @Nasreddine thanks, but it's a Windows service program so nothing to do with IIS, thanks anyway, could be a solution – Hubert Solecki May 17 '16 at 15:12
  • 1
    Well, could it be caused by that previous "request" then? maybe the error is there? – LocEngineer May 17 '16 at 15:13
  • @HubertSolecki Have you tried adding the `context.Connection.Open();` line? Also, you should post your connection string (after replacing the username/password of course) – Nasreddine May 17 '16 at 15:14
  • Which EF version? If you use EF6 you also have to use a EF6 compatible provider – magicandre1981 May 17 '16 at 15:19

1 Answers1

1

Definitely is a issue with your string connection, check it! If your credentials are right, so check doing ping to database server.

Renzo Robles
  • 684
  • 6
  • 10