Search code examples
sql-serverasp.net-mvcasp.net-mvc-3entity-frameworkmembership

ASP.NET membership using SQL Server


I am trying to create an MVC 3 app using asp.net membership in a sql server database. I want to be able to use the Entity Framework for development on this app.

I have created by database and used the aspnet_regsql utility to add the membership tables to the database. The part I'm stuck on is how to connect to this database using my application.

I have added an entity model to the project which generated a new connection string in the web.config and I have tried changing the connectionStringName property on all the membership related entries to the new string like so:

<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="BlogV1Entities" applicationName="/" />

but this is not working as I am getting errors when trying to create a user through the app or ASP.NET Configuration utility

An error occurred while attempting to initialize a System.Data.SqlClient.SqlConnection object. The value that was provided for the connection string may be wrong, or it may contain an invalid syntax. Parameter name: connectionString

Can anyone point me in the right direction to properly get this setup so my app can access the database?

EDIT: In response to first comment this is what the connection string looks like this:

 connectionString="metadata=res://*/BlogV1Model.csdl|res://*/BlogV1Model.ssdl|res://*/BlogV1Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=jesse-laptop;initial catalog=BlogV1;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Solution

  • the entity framework connection string won't work when using asp.net membership. I have dont in my project like this; i-e You need separate connection string for that;

    your membership connection string;

    <add name="DAConnection" connectionString="Data Source=.\sqlexpress;initial catalog=E:\MYWORK\DIGITALASSETSMVC3\DAMVC3\APP_DATA\DAMVC3.MDF;integrated security=True" providerName="Syste.Data.SqlClient" />
    

    you entity framework connection string;

    <add name="DAEntities" connectionString="metadata=res://*/Models.DAModel.csdl|res://*/Models.DAModel.ssdl|res://*/Models.DAModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\sqlexpress;initial catalog=E:\MYWORK\DIGITALASSETSMVC3\DAMVC3\APP_DATA\DAMVC3.MDF;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />