Connection String C # EntityFramework [closed]

-1

I would continue a work from home project, the Connection String that works is as follows:

 <add name="DBModel" connectionString="data source=PD_22;initial catalog=EXERCICIO_ENTITY_JOSEEDUARDO;user id=login;password=senha;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />

Here at home, I'm using Windows Authentication, the Connection String looks like this:

 <add name="DBModel" connectionString="data source=DESKTOP-JIJ3G7N;initial catalog=EXERCICIO_ENTITY_JOSEEDUARDO;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />

But it's not working, any suggestions? Here are some images:

{"Message": "An error has occurred.",
    "ExceptionMessage": "An error occurred while executing the command definition. See the inner exception for details.",
    "ExceptionType": "System.Data.Entity.Core.EntityCommandExecutionException",
    "StackTrace": "   em System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)\r\n   em System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)\r\n   em System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func'1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)\r\n   em System.Data.Entity.Core.Objects.ObjectQuery'1.<>c__DisplayClass7.<GetResults>b__5()\r\n   em System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func'1 operation)\r\n   em System.Data.Entity.Core.Objects.ObjectQuery'1.GetResults(Nullable'1 forMergeOption)\r\n   em System.Data.Entity.Core.Objects.ObjectQuery'1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()\r\n   em System.Data.Entity.Internal.LazyEnumerator'1.MoveNext()\r\n   em System.Collections.Generic.List'1..ctor(IEnumerable'1 collection)\r\n   em System.Linq.Enumerable.ToList[TSource](IEnumerable'1 source)\r\n   em Infrastructure.Repository.PessoaRepository.GetAll() na C:\Users\JoseEduardo\Downloads\Exercicio\Exercicio\Infrastructure\Repository\PessoaRepository.cs:linha 43\r\n   em Interface.Controllers.PessoaController.GetAll() na C:\Users\JoseEduardo\Downloads\Exercicio\Exercicio\Interface\Controllers\PessoaController.cs:linha 49\r\n   em lambda_method(Closure , Object , Object[] )\r\n   em System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   em System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary'2 arguments, CancellationToken cancellationToken)\r\n--- Fim do rastreamento de pilha do local anterior onde a exceção foi gerada ---\r\n   em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   em System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- Fim do rastreamento de pilha do local anterior onde a exceção foi gerada ---\r\n   em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   em System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- Fim do rastreamento de pilha do local anterior onde a exceção foi gerada ---\r\n   em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   em System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()",
    "InnerException": {
        "Message": "An error has occurred.",
        "ExceptionMessage": "The server principal \"IIS APPPOOL\Interface\" is not able to access the database \"EXERCICIO_ENTITY_JOSEEDUARDO\" under the current security context.\r\nCannot open database \"EXERCICIO_ENTITY_JOSEEDUARDO\" requested by the login. The login failed.\r\nLogin failed for user 'IIS APPPOOL\Interface'.\r\nErro grave no comando atual. Os resultados, se houver algum, deverão ser descartados.",
        "ExceptionType": "System.Data.SqlClient.SqlException",
        "StackTrace": "   em System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action'1 wrapCloseInAction)\r\n   em System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n   em System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)\r\n   em System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()\r\n   em System.Data.SqlClient.SqlDataReader.get_MetaData()\r\n   em System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption)\r\n   em System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)\r\n   em System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource'1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)\r\n   em System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)\r\n   em System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)\r\n   em System.Data.Entity.Infrastructure.Interception.InternalDispatcher'1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func'3 operation, TInterceptionContext interceptionContext, Action'3 executing, Action'3 executed)\r\n   em System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)\r\n   em System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)"
    }
}
    
asked by anonymous 23.10.2016 / 20:26

1 answer

2

When connecting via Windows Authentication, you need to add

Integrated Security=SSPI;

Try changing to

<add name="DBModel" connectionString="data source=DESKTOP-JIJ3G7N;initial catalog=EXERCICIO_ENTITY_JOSEEDUARDO;MultipleActiveResultSets=True;App=EntityFramework;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
    
23.10.2016 / 20:37