0
我有一个代码来打开表单时检查访问和sql server之间的连接。如果有连接,则弹出一个消息框并说明。如果没有,应该有一个消息框指示没有连接。相反,我得到的错误:其他部分的代码保持超时
Run Time Error '-2147467259 (80004005)':
[DBNETLIB][ConnectionOpen (Connect()).]Specified SQL Server Not Found
这是不是我想要它做的事,是东西在我的编码或者是有没有办法得到这个工作?
Public Sub AutoExec()
Dim cnn As ADODB.Connection
Dim localrst As New ADODB.Recordset
Dim remoterst As New ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Open "Provider=SQLOLEDB; Data Source=DB; Initial Catalog=HRLearnDev;" _
& "User Id=ID; Password=PW;"
If cnn.State = adStateOpen Then
MsgBox ("You have an established connection with the L&TD SQL Server Database.")
Else
MsgBox ("Cannot connect to remote server. Data will be stored locally to CDData Table until application is opened again.")
End If
cnn.Close
End Sub
这看起来如何?我是一个新手,当涉及到这个东西 – user2119980
我会编辑我的答案......我不知道你有多少知道。 – Floris
工作很好,第二个窗口现在弹出。但是,当我单击确定时,我得到:运行时错误3704.当对象关闭时,操作不允许。它突出显示了代码的cnn.close部分。 – user2119980