Attribute VB_Name = "shareFunction"
Public con As Connection
Dim rst As Recordset
'在网络中查找 SQL 服务器,并将其赋给 frmLand.cmbSName
Public Function getSNameList() As Boolean
Dim errVSQL As Boolean
errVSQL = True
On Error GoTo errSQL
Dim Server As SQLDMO.NameList
Dim appDMO As New SQLDMO.Application
Dim i As Integer
Set Server = appDMO.ListAvailableSQLServers
For i = 1 To Server.Count
frmLand.cmbSName.AddItem Server(i)
Next
errVSQL = False
errSQL:
If errVSQL Then
getSNameList = False
Else
getSNameList = True
End If
End Function
'当用户是使用用户名及密码验证时调用此函数
Private Function uLinkDB(SN As String, SDB As String, SUN As String, SUP As String) As Boolean
Set con = New Connection
uLinkDB = False
On Error GoTo errUSv
con.ConnectionString = "User ID =" & SUN & ";Password =" & SUP & ";Data Source=" & SN & ";Initial Catalog=" & SDB
con.Provider = "SQLOLEDB"
uLinkDB = True
errUSv:
End Function
'当用户是使用 Windows 身份验证时调用此函数
Private Function wLinkDB(SN As String, SDB As String) As Boolean
Set con = New Connection
wLinkDB = False
On Error GoTo errWSv
con.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" & SDB & ";Data Source=" & SN
con.Provider = "SQLOLEDB"
wLinkDB = True
errWSv:
End Function
'根据用户的要求选择是使用用户名,密码验证还是使用 Windows 身份验证
Public Function LinkDB(i As Integer, aSN As String, aSDB As String, aSUN As String, aSUP As String) As Boolean
If i = 0 Then
If wLinkDB(aSN, aSDB) Then
LinkDB = True
Else
LinkDB = False
End If
Else
If uLinkDB(aSN, aSDB, aSUN, aSUP) Then
LinkDB = True
Else
LinkDB = False
End If
End If
End Function
'判断是否能找到 weboy 数据库
Public Function getDB() As Boolean
Set con = New Connection
Set rst = New Recordset
getDB = False
Call LinkDB(landWay, SName, "master", SUName, SUPw)
con.Open
rst.Open "select name from sysdatabases", con, adOpenDynamic, adLockOptimistic
rst.MoveFirst
Do While Not rst.EOF
If rst!name = "weboy" Then
getDB = True
Exit Do
End If
rst.MoveNext
Loop
rst.Close
con.Close
End Function
'判断是能否在 weboy 数据库中找到表
Public Function getTheTable(theTable As String) As Boolean
''''''''''''''''''''''''''''''''''''''''''''''''''
Set con = New Connection
Set rst = New Recordset
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
getTheTable = False
Call LinkDB(landWay, SName, "weboy", SUName, SUPw)
con.Open
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rst.Open "select name from sysobjects where type='u'", con, adOpenDynamic, adLockOptimistic
rst.MoveFirst
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Do While Not rst.EOF
If rst!name = theTable Then
getTheTable = True
Exit Do
End If
rst.MoveNext
Loop
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rst.Close
con.Close
End Function