标签:vb.net tab else editor exce false word line framework
操作系统:编程环境:VS2013。 语言:VB.net; 数据库:SQLserver2008
做数据库连接时。发生的错误:
错误提示为:
说明:用VB.net连接SQLServer数据库
第一种情况:
连接字符串为“Server=(Local);Database=charge_sys;UserID = sa;Password=123456”时,连接没问题;
另外一种情况:
当把“ Server=(Local)”换为 “ Server=192.168.24.123 ”。即把local换为数据库serverIP地址时,连接不成功。出现如上错误(PS:其它人的机器上就能够)。
第一种情况的代码:
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" '与数据库建立连接 conn.Open() '操作数据库 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 '关闭与数据库的连接 conn.Close() End Function End Class另外一种情况的代码
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" '与数据库建立连接 conn.Open() '操作数据库 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 '关闭与数据库的连接 conn.Close() End Function End Class两种代码的不同之处只在于数据库连接字符串中的Server值不同。
System.AccessViolationException”类型的未经处理的异常在 System.Data.dll 中发生。其它信息:尝试读取或写入受保护的内存。这通常指示其它内存已损坏。
标签:vb.net tab else editor exce false word line framework
原文地址:http://www.cnblogs.com/gccbuaa/p/7162280.html