1

У меня есть приложение только в asp.net mvc.MVC: Проблемы с подключением к базе данных

Я пытаюсь войти в приложение через твиттер

После того как пользователь входит в систему через твиттер (который он/она успешно делает) он попадает следующую строку в ExternalLoginConfirmation методом

// Get the information about the user from the external login provider 
       var info = await AuthenticationManager.GetExternalLoginInfoAsync(); 

После выше Lind выполняется в браузере, я получаю ошибку, которая говорит

Login failed for user ''. 

Это то, что StackTrace говорит Трассировка стека:

[SqlException (0x80131904): Login failed for user ''.] 
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +347 
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78 
    System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +191 
    System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154 
    System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21 
    System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90 
    System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +166 
    System.Data.SqlClient.SqlConnection.Open() +96 
    System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c) +12 
    System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +72 
    System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +405 
    System.Data.Entity.SqlServer.<>c__DisplayClass33.<UsingConnection>b__32() +459 
    System.Data.Entity.SqlServer.<>c__DisplayClass1.<Execute>b__0() +15 
    System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +190 
    System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) +82 
    System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act) +194 
    System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act) +427 

[InvalidOperationException: This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection.] 
    System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act) +598 
    System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript) +87 
    System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) +158 
    System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) +73 
    System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase() +124 
    System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection) +112 
    System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) +141 
    System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) +79 
    System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext) +88 
    System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState) +132 
    System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) +215 
    System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +159 
    System.Data.Entity.Internal.<>c__DisplayClassf`1.<CreateInitializationAction>b__e() +76 
    System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +60 
    System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +395 
    System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) +11 
    System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +110 
    System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +214 
    System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +97 
    System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +28 
    System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +53 
    System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +16 
    System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +39 
    System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(IQueryable`1 source, Expression`1 predicate, CancellationToken cancellationToken) +154 
    System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(IQueryable`1 source, Expression`1 predicate) +163 
    Microsoft.AspNet.Identity.EntityFramework.<FindAsync>d__23.MoveNext() +948 
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 
    Microsoft.AspNet.Identity.CultureAwaiter`1.GetResult() +59 
    Microsoft.AspNet.Identity.Owin.<ExternalSignInAsync>d__1d.MoveNext() +293 
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 
    System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24 
    LangdonTwitter.Controllers.<ExternalLoginCallback>d__26.MoveNext() in C:\Users\Biplov\documents\visual studio 2015\Projects\LangdonTwitter\LangdonTwitter\Controllers\AccountController.cs:333 
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 
    System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +97 
    System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +17 
    System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32 
    System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50 
    System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225 
    System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10 
    System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34 
    System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26 
    System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100 
    System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 
    System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36 
    System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26 
    System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 
    System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28 
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +576 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157 

Я предполагаю, что он не в состоянии подключиться к базе данных

У меня есть класс DbContext в DAL проекта

public class TwitterDbContext : IdentityDbContext<User>, ITwitterDbContext 
    { 
     public TwitterDbContext() 
      : base("TwitterContextConnection") 
     { 
     } 

     public static TwitterDbContext Create() 
     { 
      return new TwitterDbContext(); 
     } 

    } 

это моя строка соединения в web.config

<connectionStrings> 
    <add name="TwitterContextConnection" connectionString="Data Source=.\SQLEXPRESS;Database=Twitter Integrated Security=True" providerName="System.Data.SqlClient" /> 
    </connectionStrings> 

Я убеждался, что работает SQLEXPRESS. Я включил миграции для базы данных с помощью PackageManagerConsole и когда я пытаюсь обновить базу данных я получаю ошибку, которая говорит

This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection. 

Есть ли что-то я делаю не так? База данных еще не существует, но я считаю, что она должна создаваться, когда она не существует.

+0

Код EF Сначала проверьте, существует ли модель для вашей базы данных в основной базе данных. См. Эту статью: http://jayhollingum.blogspot.co.uk/2011/03/ef-codefirst-databasesetinitializser.html –

ответ

1

Похоже, у вас есть ';' отсутствует между вашими значениями:

<connectionStrings> 
    <add name="TwitterContextConnection" connectionString="Data Source=.\SQLEXPRESS;Database=Twitter;Integrated Security=True";providerName="System.Data.SqlClient" /> 
</connectionStrings> 
+0

Не могу в это поверить. Кажется, работает. – Cybercop

+0

Это мелочи, которые вас поймают. www.connectionstrings.com - хорошее место для проверки! –

Смежные вопросы