This project is read-only.

Entity Framework connection string exception

Jul 2, 2013 at 11:22 AM
Hi,
I have an issue and not sure how to resolve this (I am fairly new to MVC other than following a couple of tutorials elsewhere).

I have NOT attempted to create the database and am allowing Entity Framework to try to create the database for me. I am receiving an exception in the Global.asax.cs class around line 61 (approximated as I am not sure if anything will have been inserted into this class). The line causing the issue is the call to AreaRegistration.RegisterAllAreas() method.

The exception is as follows: System.Reflection.TargetInvocationException : {Exception has been thrown by the target of an invocation }

The inner exception is as follows:

{"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."}

and the Stack Trace is :



at System.Data.Entity.ModelConfiguration.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, 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.RetryLazy2.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.InternalSet1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery
1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.Where[TSource](IQueryable1 source, Expression1 predicate)
at MVCBootstrap.EntityFramework.Repository1.ReadOne(ISpecification1 spec)
at mvcForum.Core.Abstractions.AddOnConfiguration1..ctor(IRepository1 configRepo)
at mvcForum.Core.Abstractions.AsyncAddOnConfiguration1..ctor(IRepository1 configRepo)
at mvcForum.AddOns.MultiPost.MultiPostConfiguration..ctor(IRepository`1 configRepo)

This points to my connection string or provider ...

The connection string is as follows (I am attempting to use windows Authentication to connect to my SQL Server instance which is localhost\MSSQLSERVER).
<connectionStrings>
    <add name="mvcForum.DataProvider.MainDB" connectionString="Data Source=localhost\MSSQLSERVER;Initial Catalog=ReelJiggyForum; Integrated Security=True" />
  </connectionStrings>
If it helps, I can add the whole of my web config but the membership provider is as default ....
<membership defaultProvider="ProviderWrapper">
      <providers>
        <clear />
        <add name="ProviderWrapper" type="mvcForum.Web.Providers.MembershipProviderWrapper" WrappedProvider="TheRealProvider" />
        <add name="TheRealProvider" type="MVCBootstrap.Web.Security.SimpleMembershipProvider" applicationName="mvcForum" minRequiredPasswordLength="6" />
      </providers>
    </membership>
    <roleManager enabled="true" defaultProvider="SimpleProvider">
      <providers>
        <clear />
        <add name="SimpleProvider" type="MVCBootstrap.Web.Security.SimpleRoleProvider" />
      </providers>
    </roleManager>
I'd be grateful if anyone can help me resolve this

Thanks in advance

Julian
Jul 3, 2013 at 9:31 AM
Hello Julian

I'm not sure what the issue is, but I hardly ever work with integrated security, and I'm not really sure how that works when running from a website. Are you sure the user has access to creating a database on the server? My guess is that it's not the Windows account you have that needs access, but more likely the IIS account (IUSR or AppPool user).

regards,
Steen
Jul 3, 2013 at 11:31 AM
Thanks Steen,

I am going to try and set up a user so I can use that SQL Server Authentication instead. SQL Server is not one of my strong points but thought it may be a security issue. I'll keep you posted if creating this user resolves the issue (The database instance is on my development machine at work and I have to set it up with NTAuthority as a user so I am guessing that this is probably the account I should be using)

regards

Julian
Jul 4, 2013 at 4:47 PM
Turns out in my connection string I just needed to set the Data Source to (local). I was sort of specifying the instance twice. I can now connect to the database :)
Jul 5, 2013 at 6:41 AM
Perfect, no harm done then!

Thanks,
Steen