如何测试VB和SQL Server 2000数据库的连接
2个回答
展开全部
'以下代码可以实现,不需要输入用户名和密码,就可以测试SQL连接是否正常
'之后根据结果做出下一步措施,利用账户登录或其他
Public Function Test_Sql_Connection(Server_IP As String) As String
Dim mag As String
On Error GoTo strerrmag
Set conn = New ADODB.Connection
conn.ConnectionTimeout = 2
conn.Provider = "sqloledb"
conn.Properties("data source").Value = Server_IP ''服务器的名字
conn.Properties("initial catalog").Value = "master" ''库名
conn.Properties("integrated security").Value = "SSPI" ''登陆类型
conn.Open
OpenCn = True
'addFlag = True
Test_Sql_Connection = "正常"
Exit Function
strerrmag:
Test_Sql_Connection = "服务器没有安装Sql Server或服务没有启动"
' mag = "Data can''t connect"
'
'Call MsgBox(mag, vbOKCancel, "Error:Data connect")
'addFlag = False
'End
End Function
'之后根据结果做出下一步措施,利用账户登录或其他
Public Function Test_Sql_Connection(Server_IP As String) As String
Dim mag As String
On Error GoTo strerrmag
Set conn = New ADODB.Connection
conn.ConnectionTimeout = 2
conn.Provider = "sqloledb"
conn.Properties("data source").Value = Server_IP ''服务器的名字
conn.Properties("initial catalog").Value = "master" ''库名
conn.Properties("integrated security").Value = "SSPI" ''登陆类型
conn.Open
OpenCn = True
'addFlag = True
Test_Sql_Connection = "正常"
Exit Function
strerrmag:
Test_Sql_Connection = "服务器没有安装Sql Server或服务没有启动"
' mag = "Data can''t connect"
'
'Call MsgBox(mag, vbOKCancel, "Error:Data connect")
'addFlag = False
'End
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |