2

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" />
2
  • 1
    If you look at the content of the connectionstring "BlogV1Entities", does it look like a normal SQL Server connection string or does it have weird properties with *s in them? If so, it's DB-first or model-first EF(probably 4) connection string. SqlClient doesn't use those... You can extract the connection string from your entity designer and add it as a second connection string, using that, as a simple option... Commented Jul 3, 2012 at 18:01
  • I've posted the connection string in the original post Commented Jul 3, 2012 at 18:05

2 Answers 2

4

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" />
Sign up to request clarification or add additional context in comments.

2 Comments

Ok that makes sense. This might be a silly question but is there a way to grab the proper connection string out of SQL Server?
yes, in visual studio server explorer add you connection. And that will generate connectionstring for you. u can view it by right click on the connection string and go to properties
2

It's not a valid connection string which can be used by Membership, it's kind of special connection string just can be used by EF (because of different provideName which Membership expect AFAIK).

Add a clear regular connection string and reference to it instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.