我想设置为我的数据库有效的连接字符串,使我WebSecurity.InitializeDatabaseConnection
方法可以指向我的数据库。
这里是我的连接字符串:
<add name="Database_Entities1" connectionString="metadata=res://*/Models.DAL.Entities.MTG_Model.csdl|res://*/Models.DAL.Entities.MTG_Model.ssdl|res://*/Models.DAL.Entities.MTG_Model.msl;provider=System.Data.SqlClient;provider connection string="data source=**.**.***.***;initial catalog=Model_Name;persist security info=True;user id=*****;password=*********;multipleactiveresultsets=True;application name=EntityFramework;Pooling=True;Max Pool Size=1000"" providerName="System.Data.EntityClient" />
这里的问题是供应商的名称是System.Data.EntityClient
。 我真的需要它向点System.Data.SqlClient
,但是当我试图复制/粘贴连接字符串和替换System.Data.EntityClient
与其他供应商的名字,我得到这样的碰撞就像Keyword not supported: 'metadata'.
。
所以我的理解是,打电话给我的方法是这样的:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute
{
private static SimpleMembershipInitializer _initializer;
private static object _initializerLock = new object();
private static bool _isInitialized;
public override void OnActionExecuting(ActionExecutingContext _filterContext)
{
// Ensure ASP.NET Simple Membership is initialized only once per app start
LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock);
}
private class SimpleMembershipInitializer
{
public SimpleMembershipInitializer()
{
Database.SetInitializer<Database_Entities1>(null);
try
{
using (var context = new Database_Entities1())
{
if (!context.Database.Exists())
{
// Create the SimpleMembership database without Entity Framework migration schema
((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
}
}
WebSecurity.InitializeDatabaseConnection("Database_Entities2", "UserProfile", "UserId", "UserName", true);
}
catch (Exception ex)
{
throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
}
}
}
}
其中Database_Entities2
是:
<add name="Database_Entities2" connectionString="metadata=res://*/Models.DAL.Entities.MTG_Model.csdl|res://*/Models.DAL.Entities.MTG_Model.ssdl|res://*/Models.DAL.Entities.MTG_Model.msl;provider=System.Data.SqlClient;provider connection string="data source=**.**.***.***;initial catalog=Model_Name;persist security info=True;user id=*****;password=*********;multipleactiveresultsets=True;application name=EntityFramework;Pooling=True;Max Pool Size=1000"" providerName="System.Data.SqlClient" />
不能因为一个SqlClient连接字符串不这样的。 谁能帮我achive我想要做什么? 非常感谢!
编辑
两个其它附加一条信息:我有这样的连接字符串:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MyApp-20130829080410;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MyApp-20130829080410.mdf" providerName="System.Data.SqlClient" />
这是工作; 然而,正如你所看到的,它不会对我的数据库点,所以如果我尝试检索表中的“用户配置”的任何用户,因为该表是在本地数据库中创建的(我不知道这是不可能的为什么我有),而不是在一个主体(Database_Entities1),因此这个问题。