Can SimpleMembership and Entity Framework share a connection string?

会有一股神秘感。 提交于 2019-11-28 09:49:17

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/17000869/can-simplemembership-and-entity-framework-share-a-connection-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!