这是我得到的错误:
Failed to connect to server MYSERVER. (Microsoft.sqlServer.ConnectionInfo)
ADDITIONAL informatION:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt. (System.Data)
我在使用实体框架运行任何查询时遇到此错误,例如这样的任何一行:
var AllRows = context.MyTableRows.ToList();
我认为这是一个EF问题,但后来我尝试使用VS2012中的Transact sql编辑器连接到数据库,这样我就可以查询它,并在尝试连接时遇到同样的错误.
但我有其他非Microsoft查询工具可以连接到数据库并查询它,而不会导致错误.所以我认为问题出在Microsoft驱动程序或System.Data.sqlClient的某个地方,但我无法弄清楚问题出在哪里.
更新:我尝试在LinqPad中连接到同一台服务器,当我尝试连接它时,它就会挂起.
更新:堆栈跟踪很长,看起来像这样:
at SNIAddProvider(SNI_Conn*,ProviderNum,Void* ) at SNINativeMethodWrapper.SNIAddProvider(SafeHandle pConn,ProviderEnum providerEnum,UInt32& info) at System.Data.sqlClient.TdsParser.ConsumePreLoginHandshake(Boolean encrypt,Boolean trustServerCert,Boolean integratedSecurity,Boolean& marsCapable) at System.Data.sqlClient.TdsParser.Connect(ServerInfo serverInfo,sqlInternalConnectionTds connHandler,Boolean ignoreSniOpenTimeout,Int64 timerExpire,Boolean encrypt,Boolean withFailover) at System.Data.sqlClient.sqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,securestring newSecurePassword,TimeoutTimer timeout,Boolean withFailover) at System.Data.sqlClient.sqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,Boolean redirectedUserInstance,sqlConnectionString connectionoptions,sqlCredential credential,TimeoutTimer timeout) at System.Data.sqlClient.sqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout,Boolean redirectedUserInstance) at System.Data.sqlClient.sqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity,Object providerInfo,sqlConnectionString userConnectionoptions) at System.Data.sqlClient.sqlConnectionFactory.CreateConnection(DbConnectionoptions options,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,DbConnectionPool pool,DbConnection owningConnection,DbConnectionoptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool,DbConnectionoptions options,DbConnectionoptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionoptions userOptions) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionoptions userOptions) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionoptions userOptions,DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,taskcompletionsource`1 retry,DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory,DbConnectionoptions userOptions) at System.Data.sqlClient.sqlConnection.TryOpen(taskcompletionsource`1 retry) at System.Data.sqlClient.sqlConnection.open() at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition,DbConnection storeConnectionToOpen,DbConnection originalConnection,String exceptionCode,String attemptedOperation,Boolean& closeStoreConnectionOnFailure) at System.Data.EntityClient.EntityConnection.open() at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source) at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__2[TResult](IEnumerable`1 sequence) at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query,Expression queryRoot) at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression) at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
…我的应用程序中尝试执行EF查询的行…
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。