Search code examples
mysqlentity-frameworkentity-framework-4mysql-error-1064

Entity Framework with MySql Exception - "The underlying provider failed on Open." - "Reading from the stream has failed."


We have an application that uses .NET Entity Framework 4 to connect to MySql. I've now set this up on several development machines (Windows 7) and am now deploying to Windows 2008 R2, but an exception is thrown when trying to access the database from the application.

There are two connection strings, one for use with ADO.NET and one for Entity Framework.

We are using MySql connector for .NET v 6.4.4

The exception is:

"The underlying provider failed on Open." - "Reading from the stream has failed."

When googling the exception, most posts relate to the use of Entity Framework with SqlServer, and in these cases the problem looks to be authentication related. Since we are connecting here with the root user credentials, If this is an authentication issue, I'm not sure how to diagnose. Other applications connect to the database with the same credentials.

The connection strings are:

<add name="AppEntities" connectionString="metadata=res://*/OrmApp.AppEntities.csdl|res://*/OrmApp.AppEntities.ssdl|res://*/OrmApp.AppEntities.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;User Id=root;password=*********;Persist Security Info=True;database=app_staging;Convert Zero Datetime=True&quot;" providerName="System.Data.EntityClient" />

<add name="AppAdoNet" connectionString="server=localhost;User Id=root;password=*********;Persist Security Info=True;database=app_staging;Convert Zero Datetime=True" providerName="System.Data.MySql" />

If anybody has experience of such an issue on MySql or can advise on how to diagnose the issue which I am presuming is at the database end, that would be appreciated.


Solution

  • Strange issue in the end. Answered here http://www.randombytes.me/2012/06/mysql-connector-net-reading-from-stream.html

    Updated post link.

    Summary:

    The production server was using IIS setting 'Enable 32 bit applications' set to 'True', reverting to 'False' resolved the issue. Obviously you'll need to to check if another component in your application requires this flag set 'True'.