异常无法使用ASP.NET标识创建用户

时间:2014-06-24 16:47:39

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

我在添加以下软件包后尝试将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 =   Email.Text,Email = Email.Text};第18行:IdentityResult   result = manager.Create(user,Password.Text);第19行:如果   (result.Succeeded)第20行:{

     

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

     

堆栈追踪:

     

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

     

[SqlException(0x80131904):与网络相关或特定于实例的   建立与SQL Server的连接时发生错误。该   服务器未找到或无法访问。验证该实例   名称是正确的,并且SQL Server配置为允许远程   连接。 (提供商:共享内存提供商,错误:40 - 无法   打开与SQL Server的连接)]
  System.Data.SqlClient.SqlInternalConnection.OnError(SQLEXCEPTION   exception,Boolean breakConnection,Action 1 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 retry,DbConnectionOptions   userOptions,DbConnectionInternal&连接)+78
  System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(的DbConnection   owningConnection,TaskCompletionSource 1 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   outerConnection,DbConnectionFactory connectionFactory,   TaskCompletionSource 1 retry, DbConnectionOptions userOptions) +16
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource
1   重试)+94
  System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource 1 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(t目标   目标,行动2 operation, TInterceptionContext interceptionContext, Action 3执行,行动3 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,Action 1 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&LT;&GT; c__DisplayClass1.b__0(元组3 k) +32
System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKEY的   key,Func 2 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 input)+123
  System.Data.Entity.Internal.LazyInternalContext.InitializeContext()   +610 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type   entityType)+18
  System.Data.Entity.Internal.Linq.InternalSet 1.Initialize() +52
System.Data.Entity.Internal.Linq.InternalSet
1.Include(String path)   +18 System.Data.Entity.Infrastructure.DbQuery 1.Include(String path) +64
System.Data.Entity.QueryableExtensions.Include(IQueryable
1个来源,   字符串路径)+115
  System.Data.Entity.QueryableExtensions.Include(IQueryable 1 source, Expression 1路径)+154
  Microsoft.AspNet.Identity.EntityFramework.UserStore 6.GetUserAggregateAsync(Expression 1   过滤器)+283
  Microsoft.AspNet.Identity.EntityFramework.UserStore 6.FindByNameAsync(String userName) +615
Microsoft.AspNet.Identity.UserManager
2.FindByNameAsync(字符串   userName)+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(Func 1 func) +159
Microsoft.AspNet.Identity.UserManagerExtensions.Create(UserManager
2   经理,TUser用户,字符串密码)+120
  CRMLight.Account.Register.CreateUser_Click(Object sender,EventArgs e)   在c:\ Users \ abdallaelnajjar \ Documents \ Visual Studio中   2013 \项目\ CRMLight \ CRMLight \帐户\ Register.aspx.cs:18个
  System.Web.UI.WebControls.Button.OnClick(EventArgs e)+9615682
  System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串   eventArgument)+103
  System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串   eventArgument)+10
  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler   sourceControl,String eventArgument)+13
  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)   +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean 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标识表

1 个答案:

答案 0 :(得分:1)

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

这是造成此错误的原因

  

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

也许app.config有一个很好的连接字符串用于你的单元测试与web配置有另一个连接字符串。