vb6.0中用adodc控件连接sql2005 50
vb6.0中用adodc控件链接sql2005设置connectionstring属性的时候,点击在服务器(本机)上选择数据库,总是出现[DBNETLIB][connec...
vb6.0中用adodc控件链接sql2005 设置connectionstring属性的时候,点击在服务器(本机)上选择数据库,总是出现[DBNETLIB][connectionOpen (connect()).]SQL Server 不存在或拒绝访问
为此数据库也重装过了,SQLserver服务已全部开启。。
苦苦找不到原因,急。。。。。哪位高手能指点迷津,谢了。。。。。 展开
为此数据库也重装过了,SQLserver服务已全部开启。。
苦苦找不到原因,急。。。。。哪位高手能指点迷津,谢了。。。。。 展开
2011-03-14
展开全部
VB连接SQL数据库的模块:
Public conn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public addFlag As Boolean
Public Function OpenCn() As Boolean
Dim mag As String
On Error GoTo strerrmag
Set conn = New ADODB.Connection
conn.ConnectionTimeout = 25
conn.Provider = "sqloledb"
conn.Properties("data source").Value = "127.0.0.1" ''服务器的名字
conn.Properties("initial catalog").Value = "chart" ''库名
conn.Properties("integrated security").Value = "SSPI" ''登陆类型
conn.Open
OpenCn = True
addFlag = True
Exit Function
strerrmag:
mag = "Data can''t connect"
Call MsgBox(mag, vbOKCancel, "Error:Data connect")
addFlag = False
End
End Function
Public Sub clocn()
On Error Resume Next
If conn.State <> adStateClosed Then conn.Close
Set conn = Nothing
End Sub
Public Function openrs(ByVal strsql As String) As Boolean ''连接数据库记录集
Dim mag As String
Dim rpy As Boolean
On Error GoTo strerrmag
Set rs = New ADODB.Recordset
If addFlag = False Then rpy = True
With rs
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open strsql
End With
addFlag = True
openrs = True
Exit Function
strerrmag:
mag = "data not connect"
Call MsgBox(mag, vbOKCancel, "error:connect")
openrs = False
End
End Function
Public Sub clors()
On Error Resume Next
If rs.State <> adStateClosed Then rs.Clone
Set rs = Nothing
End Sub
Public conn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public addFlag As Boolean
Public Function OpenCn() As Boolean
Dim mag As String
On Error GoTo strerrmag
Set conn = New ADODB.Connection
conn.ConnectionTimeout = 25
conn.Provider = "sqloledb"
conn.Properties("data source").Value = "127.0.0.1" ''服务器的名字
conn.Properties("initial catalog").Value = "chart" ''库名
conn.Properties("integrated security").Value = "SSPI" ''登陆类型
conn.Open
OpenCn = True
addFlag = True
Exit Function
strerrmag:
mag = "Data can''t connect"
Call MsgBox(mag, vbOKCancel, "Error:Data connect")
addFlag = False
End
End Function
Public Sub clocn()
On Error Resume Next
If conn.State <> adStateClosed Then conn.Close
Set conn = Nothing
End Sub
Public Function openrs(ByVal strsql As String) As Boolean ''连接数据库记录集
Dim mag As String
Dim rpy As Boolean
On Error GoTo strerrmag
Set rs = New ADODB.Recordset
If addFlag = False Then rpy = True
With rs
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open strsql
End With
addFlag = True
openrs = True
Exit Function
strerrmag:
mag = "data not connect"
Call MsgBox(mag, vbOKCancel, "error:connect")
openrs = False
End
End Function
Public Sub clors()
On Error Resume Next
If rs.State <> adStateClosed Then rs.Clone
Set rs = Nothing
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询