数据库链接不上啊 求大神帮忙检查一下 链接字符串
这是代码:
Public Sub Opendb()
On Error GoTo Errmsg
If Rs.state = 0 Then Rs.CursorLocation = adUseClient Else If Rs.state = 1 Then Rs.Close
If Cn.state = 0 Then
Set Cn = Nothing
Cn.ConnectionString = "Provider=sqloledb;Connect timeout=1;Data Source=" & ServerName & ";Initial Catalog=" & Dbname & ";User Id=sa;Password=" & Sa & ";"
Debug.Print "Provider=sqloledb;Connect timeout=1;Data Source=" & ServerName & ";Initial Catalog=" & Dbname & ";User Id=sa;Password=" & Sa & ";"
Cn.Open
Else
Cn.Execute "select getdate()"
End If
Exit Sub
Errmsg:
MsgBox "数据库访问失败,请检查网络连接!", vbCritical, Err.Source
End Sub
这是debug出来的链接字符串:
Provider=sqloledb;Connect timeout=1;Data Source=192.168.249.157;Initial Catalog=con2018;User Id=sa;Password=******;