gpt4 book ai didi

c# - asp.net razor 新项目无法与 mysql 建立成员关系

转载 作者:行者123 更新时间:2023-11-30 01:37:42 27 4
gpt4 key购买 nike

简单的项目,新鲜的MVC4 razor网页,新的空mysql数据库。获取此异常:

System.Reflection.TargetInvocationException was unhandled by user code
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Threading.LazyInitializer.LazyHelpers`1.ActivatorFactorySelector()
at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
at System.Threading.LazyInitializer.EnsureInitialized[T](T& target, Boolean& initialized, Object& syncLock)
at KHSWebsite.Filters.InitializeSimpleMembershipAttribute.OnActionExecuting(ActionExecutingContext filterContext) in c:\users\alex\documents\visual studio 2010\Projects\KHSWebsite\KHSWebsite\Filters\InitializeSimpleMembershipAttribute.cs:line 21
at System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeActionMethodFilterAsynchronously(IActionFilter filter, ActionExecutingContext preContext, Func`1 nextInChain)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<>c__DisplayClass3b.<BeginInvokeActionMethodWithFilters>b__35()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeActionMethodFilterAsynchronously(IActionFilter filter, ActionExecutingContext preContext, Func`1 nextInChain)
InnerException: System.InvalidOperationException
Message=The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588
Source=KHSWebsite
StackTrace:
at KHSWebsite.Filters.InitializeSimpleMembershipAttribute.SimpleMembershipInitializer..ctor() in c:\users\alex\documents\visual studio 2010\Projects\KHSWebsite\KHSWebsite\Filters\InitializeSimpleMembershipAttribute.cs:line 45
InnerException: System.InvalidOperationException
Message=The connection string 'DefaultConnection' in the application's configuration file does not contain the required providerName attribute."
Source=EntityFramework
StackTrace:
at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)
at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config)
at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName()
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.CreateObjectContextForDdlOps()
at System.Data.Entity.Database.Exists()
at KHSWebsite.Filters.InitializeSimpleMembershipAttribute.SimpleMembershipInitializer..ctor() in c:\users\alex\documents\visual studio 2010\Projects\KHSWebsite\KHSWebsite\Filters\InitializeSimpleMembershipAttribute.cs:line 34
InnerException:

这是我的 web.config:

<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=KHS;Integrated Security=SSPI;"/>
</connectionStrings>
<system.web>
<authentication mode="Forms">
<forms loginUrl="login.aspx" name=".ASPXFORMSAUTH"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
<providers>
<clear/>
<add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="DefaultConnection" applicationName="KHS" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed"/>
</providers>
</membership>
<compilation debug="true"/>
</system.web>
</configuration>

此内容已从 http://msdn.microsoft.com/en-us/library/6e9y4s5t(v=vs.100).aspx 获取并修改

有什么想法吗?谢谢

最佳答案

它表示您错过了连接字符串中的提供程序属性。您检查过该提供商了吗?

像这样的东西应该是你的连接字符串

<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Initial Catalog=ApplicationServicesDB;Integrated Security=True;MultipleActiveResultSets=True"
providerName="MySql.Data.MySqlClient"/>

此外,您还必须在 web.config 文件的 system.data 中注册 mysql。

<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.3.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>

关于c# - asp.net razor 新项目无法与 mysql 建立成员关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16626469/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com