An unhandled exception of type System.accessviolationexception "occurs in System.Data.dll. Additional information: Attempt to read or write to protected memory. This usually indicates that other memory is corrupted.

Source: Internet
Author: User


Error Background:

Operating system: Programming Environment: VS2013. Language: vb.net; database: SQLserver2008

When you make a database connection. The error that occurred:

The error message is:


Description: Connect SQL Server database with vb.net

first case:

The connection string is "server= (Local);D Atabase=charge_sys; UserID = sa; password=123456 ", the connection is not a problem;

another situation:

When you change the "server= (Local)" to "server=192.168.24.123". The connection is unsuccessful when the local is swapped for the database ServerIP address. The error appears as above (PS: The other person's machine will be able).

The first case code:

    Public Class Userdao public connstr as String = "server= (Local);D Atabase=charge_sys; User ID = sa; password=123456 "Public Function userlogin (ByVal userName As String, ByVal Password as String) as Boolean <s Pan style= "White-space:pre" ></span> Dim conn As New SqlConnection (connstr) Dim dbcmd As New Sqlcomm  and Dim reader As SqlDataReader <span style= "White-space:pre" ></span> Dim sqlstr as String = "SELECT * from User_info where [email protected] and [email protected]" ' to establish a connection conn with the database. Open () ' Operational 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 ' Close connection to database        Conn. Close () End Function End Class
Another case of code

    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 <s Pan></span> Dim conn As New SqlConnection (connstr) Dim dbcmd As New SqlCommand Dim reade R as SqlDataReader <span></span> Dim sqlstr as String = "SELECT * from User_info where [EMAIL&NBSP;PR Otected] and [email protected] "' Establish a connection to the database Conn. Open () ' Operational 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 ' Close connection to database Conn. Close () End Function   End Class 
the difference between the two codes is that the server values in the database connection string are different .


Workaround:The first method:
To reset Winsock, my system is Win7 64-bit flagship, executed as Administrator: netsh winsock reset, restarted, to be resolved.

Other System reset method or failure, can refer to Baidu encyclopedia "netsh winsock reset".
The first method:
Update the. NET Framework.


A workaround was found at VisualStudio's Feedback Center:After installing VS Unable to add data connections?. Here's a comment on this post:
        
look at vs. the version number of the. NET Framework:
        
so I went to download the latest version number.. NET Framework4.5.2(click to skip to the download link). After installation, the above problem " ' system.accessviolationexception ' type of unhandled exception occurred in System.Data.dll " getsPerfect solution.           Summary:This issue occurs in the "' System.accessviolationexception ' type of unhandled exception in System.Data.dll", which may be after installing VS2013 on the systemThe Winsock interface has an impact. So the first way to reset Winsock is to solve it, and Microsoft recently unveiled the. NET Framework4.5.2 to completely conquer the problem, so upgrading is a good choice.

There must be other reasons and solutions to this problem, assuming you have some additional, welcome to reply to me and learn from each other. Progress together.

An unhandled exception of type System.accessviolationexception "occurs in System.Data.dll. Additional information: Attempt to read or write to protected memory. This usually indicates that other memory is corrupted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.