我弄了个管理系统,因为各个窗体都需要对数据库进行访问,我把他们做了一个类来实现,但是运行程序的时候,就没有了反映,VB提示我是如下:
未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。
其他信息: 系统错误
然后停在了 SqlConn.Open()这里
请教一下高手们,是怎么回事?
Imports System.Data
Imports System.Data.SqlClient
Imports System.ComponentModel
Public Class DataBase
'实现接口IDisposable
Implements IDisposable
'数据库连接对象
Private SqlConn As SqlConnection
Public Shared sConn As String = "Persist Security Info=False;Integrated Security=SSPI;database=hisbook;server=localhost;Connect Timeout=30"
Public Sub Dispose() Implements System.IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(True)
End Sub
Protected Sub Dispose(ByVal disposing As Boolean)
If disposing <> True Then
Return
End If
If SqlConn Is Nothing = False Then
SqlConn.Dispose()
SqlConn = Nothing
End If
End Sub
Public Sub Open()
If SqlConn Is Nothing = True Then
'建立数据库连接对象
SqlConn = New SqlConnection(Me.sConn)
'打开数据库连接
SqlConn.Open()
End If
End Sub
Public Sub Close()
'如果数据库连接对象不为空则关闭数据库连接
If SqlConn Is Nothing = False Then
SqlConn.Close()
End If
End Sub
Public Function RunSelectSQL(ByVal sSQLString As System.String) As DataView
Me.Open()
Dim SqlDS As DataSet = New DataSet
Dim SqlDA As SqlDataAdapter = New SqlDataAdapter(sSQLString, Me.SqlConn)
SqlDA.Fill(SqlDS)
Return SqlDS.Tables(0).DefaultView
End Function
Public Function RunDelOrInsSQL(ByVal sSQLString As System.String)
Me.Open()
Dim SqlComm As SqlCommand = New SqlCommand(sSQLString, Me.SqlConn)
SqlComm.ExecuteNonQuery()
End Function
End Class