C# MVC连接错误:基础提供程序在打开时失败

C# MVC连接错误:基础提供程序在打开时失败,c#,asp.net,asp.net-mvc,entity-framework,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc,Entity Framework,Asp.net Mvc 4,我是ASP.NETMVC4新手。我正在尝试使用实体框架连接数据库,但未成功。 连接字符串如下所示 <add name="EmployeeContext" connectionString="Data Source=192.168.1.101;Initial Catalog=MVCPrac;User ID=sa;Password=anything" providerName="System.Data.SqlClient"/> 我得到的错误如下: System.Data.Entity

我是ASP.NETMVC4新手。我正在尝试使用实体框架连接数据库,但未成功。
连接字符串如下所示

<add name="EmployeeContext" connectionString="Data Source=192.168.1.101;Initial Catalog=MVCPrac;User ID=sa;Password=anything"  providerName="System.Data.SqlClient"/>
我得到的错误如下:

System.Data.Entity.Core.EntityException was unhandled by user code
Message=The underlying provider failed on Open.
Source=EntityFramework
StackTrace:
   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass3.<GetResults>b__1()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable`1 sequence)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.Single[TSource](IQueryable`1 source, Expression`1 predicate)
   at MVC_Trials.Controllers.EmployeeController.Details(Int32 id) in C:\Users\administrator.CRC\Documents\Visual Studio 2010\Projects\MVC Trials\MVC Trials\Controllers\EmployeeController.cs:line 19
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
InnerException: System.Data.SqlClient.SqlException
   Message=Cannot open database "MVC_Trials.Models.EmployeeContext" requested by the login. The login failed.
Login failed for user 'Test\Administrator'.
   Source=.Net SqlClient Data Provider
   ErrorCode=-2146232060
   Class=11
   LineNumber=65536
   Number=4060
   Procedure=""
   Server=.\SQLEXPRESS
   State=1
   StackTrace:
        at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
        at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
        at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
        at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
        at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
        at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
        at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
        at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
        at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
        at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
        at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
        at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
        at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
        at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
        at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
        at System.Data.SqlClient.SqlConnection.Open()
        at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c)
        at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
        at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
        at System.Data.Entity.Core.EntityClient.EntityConnection.<Open>b__2()
        at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
        at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
        at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
        at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   InnerException: 
用户代码未处理System.Data.Entity.Core.EntityException Message=基础提供程序在打开时失败。 Source=EntityFramework 堆栈跟踪: 在System.Data.Entity.Core.EntityClient.EntityConnection.Open()中 位于System.Data.Entity.Core.Objects.ObjectContext.EnsureReconnection(布尔值shouldMonitorTransactions) 在System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 Func,IDBEcutionStrategy executionStrategy,Boolean startLocalTransaction,Boolean releaseConnectionOnSuccess) 在System.Data.Entity.Core.Objects.ObjectQuery`1.c_uu DisplayClass3.b__u1()中 在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1操作)中 位于System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(可为null`1 forMergeOption) 位于System.Data.Entity.Core.Objects.ObjectQuery`1.b_u 0() 位于System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source) 位于System.Data.Entity.Core.Objects.Elink.ObjectQueryProvider.b__3[TResult](IEnumerable`1序列) 位于System.Data.Entity.Core.Objects.Elink.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1查询,表达式queryRoot) 位于System.Data.Entity.Core.Objects.Elink.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](表达式) 在System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](表达式)处 at System.Linq.Queryable.Single[TSource](IQueryable`1 source,表达式`1谓词) 在C:\Users\administrator.CRC\Documents\visualstudio 2010\Projects\MVC Trials\MVC Trials\Controllers\EmployeeController.Details(Int32 id)中的MVC\u Trials.Controllers.EmployeeController.Details(Int32 id):第19行 在lambda_方法中(闭包、控制器基、对象[]) 位于System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller,Object[]参数) 位于System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext ControllerContext,IDictionary`2参数) 位于System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor,IDictionary`2参数) 在System.Web.Mvc.Async.AsyncControllerActionInvoker.c__DisplayClass42.b__41()中 在System.Web.Mvc.Async.AsyncResultRapper.c_uuu显示类8`1.b_uuu7(IAsyncResult) 位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncResult`1.End() 位于System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) 在System.Web.Mvc.Async.AsyncControllerActionInvoker.c_uuDisplayClass37.c_uuDisplayClass39.b_u33()中 在System.Web.Mvc.Async.AsyncControllerActionInvoker.c__DisplayClass4f.b__49()中 InnerException:System.Data.SqlClient.SqlException Message=无法打开登录请求的数据库“MVC_Trials.Models.EmployeeContext”。登录失败。 用户“测试\管理员”登录失败。 Source=.Net SqlClient数据提供程序 错误代码=-2146232060 等级=11 行号=65536 数字=4060 Procedure=“” 服务器=。\SQLEXPRESS 状态=1 堆栈跟踪: 位于System.Data.SqlClient.SqlInternalConnection.OneError(SqlException异常,布尔断开连接) 位于System.Data.SqlClient.TdsParser.throweexception和warning()处 在System.Data.SqlClient.TdsParser.Run(RunBehavior RunBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj) 位于System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(布尔值登记OK) 位于System.Data.SqlClient.SqlInternalConnectionDS.AttemptOneLogin(ServerInfo ServerInfo、字符串newPassword、布尔值IgnoresInOpenTimeout、TimeoutTimer timeout、SqlConnection owningObject) 位于System.Data.SqlClient.SqlInternalConnectionDS.LoginOfAliver(ServerInfo服务器信息、字符串newPassword、Boolean redirectedUserInstance、SqlConnectionOwningObject、SqlConnectionString连接选项、超时超时) 位于System.Data.SqlClient.SqlInternalConnectionDS.OpenLoginList(SqlConnection owningObject、TimeoutTimer timeout、SqlConnectionString connectionOptions、String newPassword、Boolean redirectedUserInstance) 位于System.Data.SqlClient.SqlInternalConnectionDS..ctor(DbConnectionPoolIdentity、SqlConnectionString connectionOptions、Object providerInfo、String newPassword、SqlConnection owningObject、Boolean redirectedUserInstance) 位于System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项、对象池组ProviderInfo、DbConnectionPool池、DbConnection所有者连接) 位于System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection所有者连接、DbConnectionPool池、DbConnectionOptions选项) 位于System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) 位于System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) 位于System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) 位于System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection-owningConnection) 位于System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory) 在System.Data.SqlClient.SqlConnection.Open()处 在System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b_u36(DbConnection t,DbConnectionInterceptionContext c) 在System.Data.Entity.Infrastructure.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget,Action`2 operation,TInterceptionContext interceptionContext,Action`3 executing,Action`3 executed) 在System.Data.Entity.Infrast
System.Data.Entity.Core.EntityException was unhandled by user code
Message=The underlying provider failed on Open.
Source=EntityFramework
StackTrace:
   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass3.<GetResults>b__1()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable`1 sequence)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.Single[TSource](IQueryable`1 source, Expression`1 predicate)
   at MVC_Trials.Controllers.EmployeeController.Details(Int32 id) in C:\Users\administrator.CRC\Documents\Visual Studio 2010\Projects\MVC Trials\MVC Trials\Controllers\EmployeeController.cs:line 19
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
InnerException: System.Data.SqlClient.SqlException
   Message=Cannot open database "MVC_Trials.Models.EmployeeContext" requested by the login. The login failed.
Login failed for user 'Test\Administrator'.
   Source=.Net SqlClient Data Provider
   ErrorCode=-2146232060
   Class=11
   LineNumber=65536
   Number=4060
   Procedure=""
   Server=.\SQLEXPRESS
   State=1
   StackTrace:
        at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
        at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
        at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
        at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
        at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
        at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
        at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
        at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
        at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
        at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
        at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
        at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
        at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
        at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
        at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
        at System.Data.SqlClient.SqlConnection.Open()
        at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c)
        at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
        at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
        at System.Data.Entity.Core.EntityClient.EntityConnection.<Open>b__2()
        at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
        at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
        at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
        at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   InnerException: 
public class EmployeeContext : DbContext
{
    public DbSet<Employee> Employees { get; set; }
}
public EmployeeContext() : base("EmployeeContext")
{
}