Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

web config - Can SimpleMembership and Entity Framework share a connection string?

Currently when using Entity Framework and SimpleMembership I need to have 2 connection strings in web.config.

The first is used when calling WebSecurity.InitializeDatabaseConnection and its a simple connection string. The other is for the edmx and contains file references and the connection string info. It means the connection string info is in the file twice.

As well as duplicating information, I believe it can be an issue using azure (unconfirmed).

Is there a way to reduce this to one connection string and just keep the one for the edmx. Simply passing the EF one to the WebSecurity initialization method does not work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes you can use the same connection string for both. The difference is that the connection string for the edmx contains extra metadata for the model.

Best bet would be to just have the edmx connection string, then parse it with the EntityConnectionStringBuilder.

var builder = new EntityConnectionStringBuilder(entityConnectionString);
string sqlConnString = builder.ConnectionString;

Then initialise SimpleMembershipProvider with that connection string

WebSecurity.InitializeDatabaseConnection(sqlConnString, "User", "UserId", "UserName", autoCreateTables: true);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...