sql-server – 尝试读取或写入连接到SQL Server的受保护内存

前端之家收集整理的这篇文章主要介绍了sql-server – 尝试读取或写入连接到SQL Server的受保护内存前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我得到的错误

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查询的行…

解决方法

从.NET 4.5升级到.NET 4.5.1后,我遇到了同样的问题.当我尝试使用Entity Framework访问任何内容时,我收到了该错误.为我修复的是运行此命令(在管理员提示符中):

netsh winsock重置

然后重启.

猜你在找的MsSQL相关文章