System.accessviolationexception "type of unhandled exception occurred in System.Data.dll

Source: Internet
Author: User


Error Background:

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

Error occurred while doing database connection:

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;

second case:

When the "server= (local)" to "server=192.168.24.123", that is, the local exchange for the database server IP address, the connection is unsuccessful, such as the error (PS: Other people on the machine can be).

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
The second case 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 are different in the database connection string only .


Workaround:The first method:
Reset Winsock, my system for Win7 64-bit flagship, run as Administrator: netsh winsock reset, restart, get resolved. Other system reset methods or problems, can refer to the 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? , there is a comment below this post:
        
look at the version of the. NET framework in VS:
        
so I went to download the latest version of the. NET Framework4.5.2(click to skip to 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 method of resetting Winsock can be resolved, and Microsoft's recently released. NET Framework4.5.2 has completely solved the problem, so upgrading is also a good choice.        There must be other reasons and solutions to this problem, if you have some additional, you are welcome to give me a reply, learn from each other and make progress together.

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.