Page 1 of 1

ProviderManifestToken with EF 4.2 code first

Posted: Thu 10 Nov 2011 10:23
by object
Hei,

I am rewriting some code to use EF code first and DbContext. In one of earlier threads it was said that connection string name and context class name should match. However I am getting "The provider did not return a ProviderManifestToken string" exception when I try to open the database.

Here is my old connection string (works fine):





This works fine with old (database first) model.

I have rewritten the connection string to look like this:





and here is the context class:

Code: Select all

    public class GranittEntities : DbContext
    {
        public GranittEntities() : base()
        {
            Database.SetInitializer(null);
        }

        public GranittEntities(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {
            Database.SetInitializer(null);
        }

        public ObjectContext ObjectContext
        {
            get { return (this as IObjectContextAdapter).ObjectContext; }
        }

        public DbSet Roles { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove();
            string schemaName = GetSchemaName();
            modelBuilder.Entity().ToTable("EdmMetadata", schemaName);

            modelBuilder.Configurations.Add(new RolesConfiguration(schemaName));

            base.OnModelCreating(modelBuilder);
        }

        private string GetSchemaName()
        {
            foreach (var item in Database.Connection.ConnectionString.Split(';'))
            {
                if (item.Trim().ToLower().StartsWith("user id"))
                {
                    return item.Split('=')[1].Trim().ToUpper();
                }
            }
            return null;
        }
    }
However, attempt to open the database fails with the following exception:

Code: Select all

Test 'CodeFirstTests.GranittModelCodeFirstTests.add_to_roles_should_update_item_collection' failed: System.Data.ProviderIncompatibleException : The provider did not return a ProviderManifestToken string.
  ----> System.InvalidOperationException : Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.
	at System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
	at System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
	at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
	at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
	at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
	at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
	at System.Data.Entity.Internal.InternalContext.Initialize()
	at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
	at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
	at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
	at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
	at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
	CodeFirstTests\Tests.cs(27,0): at CodeFirstTests.GranittModelCodeFirstTests.add_to_roles_should_update_item_collection()
	--InvalidOperationException
	at Devart.Common.DbConnectionFactory.a(DbConnectionBase A_0)
	at Devart.Common.DbConnectionClosed.Open(DbConnectionBase outerConnection)
	at Devart.Common.DbConnectionBase.Open()
	at Devart.Data.Oracle.OracleConnection.Open()
	at Devart.Common.Entity.a1.a(DbConnection A_0)
	at Devart.Data.Oracle.Entity.j.a(OracleConnection A_0, Boolean A_1)
	at Devart.Data.Oracle.Entity.OracleEntityProviderServices.GetDbProviderManifestToken(DbConnection connection)
	at System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
I tried both ctx = new GranittEntities("GranittEntities") and ctx = new GranittEntities(). They both fail.

Posted: Fri 11 Nov 2011 15:10
by Shalex
object wrote:I am rewriting some code to use EF code first and DbContext. In one of earlier threads it was said that connection string name and context class name should match.
This is correct.

1. Try using the latest (6.50.244) build of dotConnect for Oracle. It includes the fix for the bug with returning invalid connections to pool. Hope this will help.
2. Make sure that the project, in which EF Code-First approach is used, has neither *.edmx nor *.edml files additionally.

Posted: Mon 14 Nov 2011 07:48
by object
Nope. New version (6.50.244) didn't help.

Test 'CodeFirstTests.add_to_roles_should_update_item_collection' failed: System.Data.ProviderIncompatibleException : The provider did not return a ProviderManifestToken string.
----> Devart.Data.Oracle.OracleException : Can not load Oracle client. Check your PATH environment variable and registry settings.

I named the connection string after the name of the context class. The project does not have edmx or edml items.

Posted: Tue 15 Nov 2011 15:59
by Shalex
object wrote:Devart.Data.Oracle.OracleException : Can not load Oracle client. Check your PATH environment variable and registry settings.
This is a general (not Entity Framework - specific) error. Please refer to this thread: http://www.devart.com/forums/viewtopic.php?t=14417.

If this doesn't help, tell us:
1) the installation type (Instant Client or Administrator) of your Oracle client;
2) does this Oracle client instance work if you are using it with another provider (or tool)?