cool hit counter Unhandled exception of type "System.AccessViolationException" raised in System.Data.dll. Additional information: attempt to read or write to protected memory. This usually indicates that other memory is corrupted._Intefrankly

Unhandled exception of type "System.AccessViolationException" raised in System.Data.dll. Additional information: attempt to read or write to protected memory. This usually indicates that other memory is corrupted.


Copyright: This is an original post by the blogger and may not be reproduced without the blogger's permission. https://blog.csdn.net/huyuyang6688/article/details/28388659

Error Background.

operating system: Programming environment:VS2013; language:VB.net; databases:SQLserver2008

Errors occurring when doing database connections.

The error message reads.

Description: Connecting to a SQLServer database with VB.net

First scenario.

The connection string is "Server=(Local);Database=charge_sys; UserID = sa; Password=123456", the connection is OK.

Second scenario.

When replacing " Server=(Local)" with " Server=192.168.24.123", i.e. replacing local with the database server IP address, the connection does not work and the error appears as above (PS: it works on other people's machines).

Code for the first case.

    Public Class UserDAO
        Public connStr As String = "Server=(Local);Database=charge_sys;User ID = sa;Password=123456"
        Public Function UserLogin(ByVal userName As String, ByVal password As String) As Boolean
     <span style="white-space:pre">	</span>    Dim conn As New SqlConnection(connStr)
            Dim dbcmd As New SqlCommand
            Dim reader As SqlDataReader
       <span style="white-space:pre">	</span>    Dim sqlStr As String = "select * from User_Info where userID=@userName and PWD=@password"
            ' Establishing a connection to the database
            conn.Open()
            ' Operating the database
            dbcmd = New SqlCommand(sqlStr, conn)
            dbcmd.Parameters.Add(New SqlParameter("@userName", userName))
            dbcmd.Parameters.Add(New SqlParameter("@password", password))
            reader = dbcmd.ExecuteReader
            If reader.Read Then
                Return True
            Else
                Return False
            End If
            ' Closing the connection to the database
            conn.Close()
        End Function
    End Class

The code for the second case

    Public Class UserDAO
        Public connStr As String = "Server=192.168.24.123;Database=charge_sys;User ID = sa;Password=123456"
        Public Function UserLogin(ByVal userName As String, ByVal password As String) As Boolean
     <span>	</span>    Dim conn As New SqlConnection(connStr)
            Dim dbcmd As New SqlCommand
            Dim reader As SqlDataReader
       <span>	</span>    Dim sqlStr As String = "select * from User_Info where userID=@userName and PWD=@password"
            ' Establishing a connection to the database
            conn.Open()
            ' Operating the database
            dbcmd = New SqlCommand(sqlStr, conn)
            dbcmd.Parameters.Add(New SqlParameter("@userName", userName))
            dbcmd.Parameters.Add(New SqlParameter("@password", password))
            reader = dbcmd.ExecuteReader
            If reader.Read Then
                Return True
            Else
                Return False
            End If
            ' Closing the connection to the database
            conn.Close()
        End Function
    End Class

The difference between the two codes It is only the Server value in the database connection string that differs

Solution.

First method.

reprovisionwinsock, My system isWin7 64 Bit Flagship Edition, Run as administrator:netshwinsockreset , reopen, settle。 Other system reset methods or problems, Refer to Baidu Encyclopedia《netsh winsock reset》

First method.

NET Framework update.

The solution was found in VisualStudio's Feedback Center atAfter installing VS 2013 unable to add data connections?, there is this comment under this post.

Looking at the version of the .NET Framework in VS.

So went and downloaded the latest version of.NET Framework4.5.2 (click to jump to the download link), after installing the above issue" Unhandled exception of type 'System.AccessViolationException' raised in System.Data.dll " Get the perfect solution.

To sum up.

This problem has occurred“‘System.AccessViolationException’ Unhandled exceptions of type System.Data.dll occur in”, It could be that the installationVS2013 After the system for thewinsock Interfaces have an impact, So the first method resetswinsock It can be solved; Microsoft just released in the last few days.NET Framework4.5.2 It also solves the problem once and for all, So an upgrade would be a good option。

There must be other reasons and solutions for such problems, if you have something to add, you are welcome to reply to me, learn from each other and make progress together.


Recommended>>
1、Turtle Programming Lite 37
2、Blockchain do you really understand
3、The Ultimate Test opens tomorrow as the Magic Advance Corps assembles
4、DSGE Modeling and Programming Dynare Estimation
5、Robot football team with AI capabilities

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号