Bug #60283 Entity Framework 4 - ProviderIncompatibleException
Submitted: 28 Feb 2011 18:00 Modified: 28 Feb 2011 20:57
Reporter: Richard Deeming Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.3.6 OS:Windows (7 x64)
Assigned to: CPU Architecture:Any

[28 Feb 2011 18:00] Richard Deeming
Description:
The GetDbProviderManifestToken method of the MySqlProviderServices attempts to open a connection to the database in order to return the MySql version number.

If the database doesn't exist yet - for example, when using the code-first "context.Database.Exists()" method - this results in a ProviderIncompatibleException being thrown.

This also means that it's not possible to generate a script to create the database using EF4 unless the database already exists.

How to repeat:
Create an entity data model for a new database which doesn't exist yet.

Attempt to generate the script to create the database.

Result:
-------
System.Data.ProviderIncompatibleException
  The provider did not return a ProviderManifestToken string.

  StackTrace:
    Server stack trace: 
       at System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
       at System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
       at System.Data.Entity.ModelConfiguration.ModelBuilder.Build(DbConnection providerConnection)
       at System.Data.Entity.Internal.LazyInternalContext.CreateModel()
       at System.Lazy`1.CreateValue()

    Exception rethrown at [0]: 
       at System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
       at System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
       at System.Data.Entity.ModelConfiguration.ModelBuilder.Build(DbConnection providerConnection)
       at System.Data.Entity.Internal.LazyInternalContext.CreateModel()
       at System.Lazy`1.CreateValue()
       at System.Lazy`1.LazyInitValue()
       at System.Lazy`1.get_Value()
       at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
       at System.Data.Entity.Internal.LazyInternalContext.GetObjectContextWithoutDatabaseInitialization()
       at System.Data.Entity.Database.DbDatabase.Exists()
       at App.VerifyDatabase()

  InnerException: MySql.Data.MySqlClient.MySqlException
       Access denied for user 'myuser'@'%' to database 'mydatabase'
       ErrorCode=-2147467259
       Number=1044
       StackTrace:
            at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
            at MySql.Data.MySqlClient.NativeDriver.AuthenticateNew()
            at MySql.Data.MySqlClient.NativeDriver.Authenticate()
            at MySql.Data.MySqlClient.NativeDriver.Open()
            at MySql.Data.MySqlClient.Driver.Open()
            at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
            at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
            at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
            at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
            at MySql.Data.MySqlClient.MySqlPool.GetConnection()
            at MySql.Data.MySqlClient.MySqlConnection.Open()
            at MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection connection)
            at System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)

Suggested fix:
If the database doesn't exist, fall back to a different database. 
(For example, the MS-SQL provider falls back to the "master" database.)

If the connection still fails, fall back to a reasonable default.
(The MS-SQL provider doesn't currently do this, but it would probably be a good idea.)
[28 Feb 2011 19:22] Valeriy Kravchuk
Looks like related to/a duplicate of Bug #59168. Please, check.
[28 Feb 2011 19:34] Richard Deeming
It looks like it could be related, but I wouldn't say it's a duplicate. #59168 seems to deal with errors connecting to an existing database; I'm getting an error trying to check when a new database exists.

Obviously this isn't something that needs to be done regularly, but it would be nice if we could detect when the database doesn't exist and generate a script to create it.
[28 Feb 2011 20:44] Richard Deeming
Never mind - after testing with an existing database, I've discovered that the MySql connector doesn't support generating the "create database" script at all:

System.Data.ProviderIncompatibleException: 
CreateDatabaseScript is not supported by the provider.
   at System.Data.Common.DbProviderServices.DbCreateDatabaseScript(String providerManifestToken, StoreItemCollection storeItemCollection)
   at System.Data.Objects.ObjectContext.CreateDatabaseScript()

The MySqlProviderServices class would need to override the DbCreateDatabaseScript(string, StoreItemCollection) method to support this.
[28 Feb 2011 20:57] Richard Deeming
Looks like the same problems as Bug #59168.