【问题标题】:Exception can't create user using ASP.NET Identity异常无法使用 ASP.NET 标识创建用户
【发布时间】:2014-06-24 16:47:39
【问题描述】:

我在添加以下包后尝试将 ASP.net Web 应用程序连接到 SQL Server Enterprise 版时遇到问题:

Microsoft.AspNet.Identity.OWIN
Microsoft.AspNet.Identity.Core 
Microsoft.AspNet.Identity.EntityFramework

当我尝试注册用户时,我收到此错误异常。 我创建了一个测试方法来测试连接是否正常工作并且它可以很好地连接到我的数据库服务器。 例外:

异常详细信息:System.ComponentModel.Win32Exception:系统 找不到指定的文件

来源错误:

第 16 行:var manager = Context.GetOwinContext().GetUserManager(); 第 17 行:var user = new ApplicationUser() { UserName = 电子邮件. 文本,电子邮件 = 电子邮件. 文本 };第 18 行:身份结果 结果 = manager.Create(user, Password.Text);第 19 行:如果 (result.Succeeded) 第 20 行:{

源文件:c:\Users\abdallaelnajjar\Documents\Visual Studio 2013\Projects\CRMLight\CRMLight\Account\Register.aspx.cs 行:18

堆栈跟踪:

[Win32Exception (0x80004005): 系统找不到文件 指定]

[SqlException (0x80131904): 网络相关或实例特定 建立与 SQL Server 的连接时出错。这 服务器未找到或无法访问。验证实例 名称正确且 SQL Server 配置为允许远程 连接。 (提供者:共享内存提供者,错误:40 - 无法 打开与 SQL Server 的连接)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException 异常,布尔 breakConnection,Action1 wrapCloseInAction) +5340655 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +244
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5350915
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +922
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +307
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +518
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +278
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +732
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +85
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1057
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource
1 重试,DbConnectionOptions 用户选项,DbConnectionInternal& 连接)+78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +196
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1 重试, DbConnectionOptions userOptions) +146
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection 外部连接,DbConnectionFactory 连接工厂, 任务完成源1 retry, DbConnectionOptions userOptions) +16
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource
1 重试)+94
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) +110 System.Data.SqlClient.SqlConnection.Open() +96
System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__38(DbConnection t, DbConnectionInterceptionContext c) +10
System.Data.Entity.Infrastructure.Interception.InternalDispatcher
1.Dispatch(TTarget 目标,Action2 operation, TInterceptionContext interceptionContext, Action3 正在执行,Action3 executed) +72
System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +360
System.Data.Entity.SqlServer.<>c__DisplayClass31.<UsingConnection>b__2f() +337 System.Data.Entity.SqlServer.<>c__DisplayClass1.<Execute>b__0() +10
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func
1 操作)+189
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(操作 操作)+78
System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action1 act) +238
System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action
1 act) +556
System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifestToken(DbConnection 连接)+250
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection 连接)+87

[ProviderIncompatibleException: 提供者没有返回 ProviderManifestToken 字符串。]
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection 连接)+271
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices,DbConnection 连接)+33

[ProviderIncompatibleException: 访问 数据库。这通常意味着与数据库的连接 失败的。检查连接字符串是否正确,并且 正在使用适当的 DbContext 构造函数来指定它或查找 它在应用程序的配置文件中。看 http://go.microsoft.com/fwlink/?LinkId=386386 获取有关信息 DbContext 和连接。有关详细信息,请参阅内部异常 失败。]
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices,DbConnection 连接)+246
System.Data.Entity.Infrastructure.c__DisplayClass1.b__0(Tuple3 k) +32
System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey 键,Func2 valueFactory) +72
System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection) +251
System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) +56
System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +43
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +62
System.Data.Entity.Internal.RetryLazy
2.GetValue(TInput 输入) +123
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +610 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(类型 实体类型)+18
System.Data.Entity.Internal.Linq.InternalSet1.Initialize() +52
System.Data.Entity.Internal.Linq.InternalSet
1.Include(字符串路径) +18 System.Data.Entity.Infrastructure.DbQuery1.Include(String path) +64
System.Data.Entity.QueryableExtensions.Include(IQueryable
1 来源, 字符串路径)+115
System.Data.Entity.QueryableExtensions.Include(IQueryable1 source, Expression1 路径) +154
Microsoft.AspNet.Identity.EntityFramework.UserStore6.GetUserAggregateAsync(Expression1 过滤器)+283
Microsoft.AspNet.Identity.EntityFramework.UserStore6.FindByNameAsync(String userName) +615
Microsoft.AspNet.Identity.UserManager
2.FindByNameAsync(字符串 用户名) +56
Microsoft.AspNet.Identity.d__4.MoveNext() +392
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+52 Microsoft.AspNet.Identity.d__0.MoveNext() +251 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+52 Microsoft.AspNet.Identity.d__0.MoveNext() +675 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+52 Microsoft.AspNet.Identity.d__d.MoveNext() +581 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+52 Microsoft.AspNet.Identity.AsyncHelper.RunSync(Func1 func) +159
Microsoft.AspNet.Identity.UserManagerExtensions.Create(UserManager
2 管理员,TUser 用户,字符串密码)+120
CRMLight.Account.Register.CreateUser_Click(对象发送者,EventArgs e) 在 c:\Users\abdallaelnajjar\Documents\Visual Studio 2013\Projects\CRMLight\CRMLight\Account\Register.aspx.cs:18
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9615682
System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串 事件参数)+103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,字符串 eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint) +1724 我的连接字符串

  <add name="crmlightEntities" connectionString="metadata=res://*/Models.CRMLightModel.csdl|res://*/Models.CRMLightModel.ssdl|res://*/Models.CRMLightModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=sqlserver;initial catalog=crmlight;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>

只是在我安装软件包时的措辞,它应该是 ASP.NET Identity 的安装表

【问题讨论】:

    标签: c# asp.net .net sql-server entity-framework


    【解决方案1】:

    检查您的数据库连接 - 您的应用程序无法连接到数据库。 它将位于 ConnectionSettings 的 web.config 文件中。

    这就是这个错误的原因

    在建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:共享内存提供者,错误:40 - 无法打开与 SQL Server 的连接)

    也许 app.config 为您的单元测试提供了一个很好的连接字符串,而 web config 有另一个连接字符串。

    【讨论】:

    • 嗨,我添加了连接字符串
    猜你喜欢
    • 1970-01-01
    • 2017-01-05
    • 2016-02-22
    • 2014-01-24
    • 2016-04-25
    • 2014-02-16
    • 2013-11-24
    • 2018-12-16
    • 1970-01-01
    相关资源
    最近更新 更多