Ive spent a few days trying to get simple membership to work with entityframework (5) and It just refuses to connect to my DB
In my solution I currently have 2 projects, a data layer that has an edmx file generated from an exiting database. In this project I have an app.config file that has a connection string pointing to an existing database. This process worked ok and I have
an edmx file with all the tables in the database.
I then have an mvs (4) project setup as an internet app, so its included the relevant account controllers, views and models. My DB has the relevant tables necessary for simple membership and a UserProfile table. Thses are the relevant parts of my web.config
file
as soon as I try to execute this line, I get errors
[ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.]
WebMatrix.Data.DbProviderFactoryWrapper.CreateConnection(String connectionString) +32476
WebMatrix.Data.Database.EnsureConnectionOpen() +32
WebMatrix.Data.<QueryInternal>d__0.MoveNext() +79
System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +247
WebMatrix.WebData.SimpleMembershipProvider.CheckTableExists(IDatabase db, String tableName) +90
WebMatrix.WebData.SimpleMembershipProvider.CreateTablesIfNeeded() +64
WebMatrix.WebData.WebSecurity.InitializeMembershipProvider(SimpleMembershipProvider simpleMembership, DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean createTables) +95
WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +86
EbsMVC.Filters.SimpleMembershipInitializer..ctor() in c:\Projects\EbsMVC\EbsMVC\Filters\InitializeSimpleMembershipAttribute.cs:41
[InvalidOperationException: The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588]
EbsMVC.Filters.SimpleMembershipInitializer..ctor() in c:\Projects\EbsMVC\EbsMVC\Filters\InitializeSimpleMembershipAttribute.cs:47
Im new to mvc4, so any help would be greatly appreciated
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.
at System.Data.Entity.ModelConfiguration.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
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.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()
the strange thing is, in my data layer project ive created an edmx page and hooked it into the database to generate the necessary classes and this process worked fine. I basically copied the connection string from the app.config file in the data layer into
the web config file of the mvc app. The data layer had no reference to webmatrix. Could it be this section thats casing the problem ? As I mentioned mvc4 is new to me so ive got a few hurdles to jump
misuk11
Participant
1608 Points
1282 Posts
MVC 4 SimpleMembership
Jan 11, 2013 10:03 AM|LINK
Ive spent a few days trying to get simple membership to work with entityframework (5) and It just refuses to connect to my DB
In my solution I currently have 2 projects, a data layer that has an edmx file generated from an exiting database. In this project I have an app.config file that has a connection string pointing to an existing database. This process worked ok and I have an edmx file with all the tables in the database.
I then have an mvs (4) project setup as an internet app, so its included the relevant account controllers, views and models. My DB has the relevant tables necessary for simple membership and a UserProfile table. Thses are the relevant parts of my web.config file
<configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <connectionStrings> <add name="EBSEntities" connectionString="metadata=res://*/EbsDataModel.csdl|res://*/EbsDataModel.ssdl|res://*/EbsDataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=PC\MSSQLSERVER2008;initial catalog=EBS;user id=user id here;password=user password here;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" /> <add name="MembershipConnection" connectionString="packet size=4096;user id=user id here;data source=PC\MSSQLSERVER2008;persist security info=True;initial catalog=EBS;password=password here;" providerName="System.Data.SqlClient" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> </entityFramework> <roleManager enabled="true" defaultProvider="simple"> <providers> <clear/> <add name="simple" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"/> </providers> </roleManager> <membership defaultProvider="simple"> <providers> <clear/> <add name="simple" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/> </providers> </membership>in the InitializeSimpleMembershipAttribute class I have this line
WebSecurity.InitializeDatabaseConnection("EBSEntities", "UserProfile", "UserId", "UserName", autoCreateTables: true);
as soon as I try to execute this line, I get errors
Im new to mvc4, so any help would be greatly appreciated
misuk11
Participant
1608 Points
1282 Posts
Re: MVC 4 SimpleMembership
Jan 11, 2013 10:50 AM|LINK
Im also getting this error
The entity type UserProfile is not part of the model for the current context
so it cant even see the new table, despite it existing in the db AND in the edmx
im really stumped and cant get past this
pieterv
Member
66 Points
14 Posts
Re: MVC 4 SimpleMembership
Jan 11, 2013 11:42 AM|LINK
Hi there,
Have you tried removing the metdata bit from the connectionString? i.e. instead of
User something like this:
Blog | Twitter : @pietervander
misuk11
Participant
1608 Points
1282 Posts
Re: MVC 4 SimpleMembership
Jan 11, 2013 12:05 PM|LINK
but thats not an entity framework connection string
pieterv
Member
66 Points
14 Posts
Re: MVC 4 SimpleMembership
Jan 11, 2013 12:06 PM|LINK
Whoops, sorry. Just noticed you're not using code-first?
Blog | Twitter : @pietervander
CPrakash82
All-Star
18722 Points
2900 Posts
Re: MVC 4 SimpleMembership
Jan 11, 2013 12:17 PM|LINK
Try replacing your provider with - System.Data.SqlClient and see if it works.
misuk11
Participant
1608 Points
1282 Posts
Re: MVC 4 SimpleMembership
Jan 11, 2013 01:38 PM|LINK
got a different error after I made that change
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.
at System.Data.Entity.ModelConfiguration.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
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.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()
CPrakash82
All-Star
18722 Points
2900 Posts
Re: MVC 4 SimpleMembership
Jan 11, 2013 02:36 PM|LINK
You can revert the providername to System.Data.EntityClient and try reinstalling webmatrix.
misuk11
Participant
1608 Points
1282 Posts
Re: MVC 4 SimpleMembership
Jan 11, 2013 03:28 PM|LINK
the strange thing is, in my data layer project ive created an edmx page and hooked it into the database to generate the necessary classes and this process worked fine. I basically copied the connection string from the app.config file in the data layer into the web config file of the mvc app. The data layer had no reference to webmatrix. Could it be this section thats casing the problem ? As I mentioned mvc4 is new to me so ive got a few hurdles to jump
<roleManager enabled="true" defaultProvider="simple">
<providers>
<clear/>
<add name="simple" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"/>
</providers>
</roleManager>
<membership defaultProvider="simple">
<providers>
<clear/>
<add name="simple" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
</providers>
</membership>
CPrakash82
All-Star
18722 Points
2900 Posts
Re: MVC 4 SimpleMembership
Jan 12, 2013 12:02 AM|LINK
You should be using DefaultMembershipProvider liek below, please refer here for more info.