我的程序:
Dim str As String
Dim strr As String
strr = CommonDialog1.FileName
str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strr & ";Persist Security Info=False"
Adodc1.ConnectionString = str
Adodc1.RecordSource = " select * from salary "
Set DataGrid1.DataSource = Adodc1
Adodc1.Refresh
这样是成功联接了,但不知有没有一段程序来测试连接(如果连错的话可以知道).
请各位高人指点一下小弟.
Dim str As String
Dim strr As String
strr = CommonDialog1.FileName
str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strr & ";Persist Security Info=False"
Adodc1.ConnectionString = str
Adodc1.RecordSource = " select * from salary "
Set DataGrid1.DataSource = Adodc1
Adodc1.Refresh
这样是成功联接了,但不知有没有一段程序来测试连接(如果连错的话可以知道).
请各位高人指点一下小弟.
解决方案 »
- 请教哪有VB+GIS开发方面的资料?
- 无聊~~~ 散分了~~
- 求高手指点:怎样用VB提取WORD文档的表格中红色的文字到TEXTBOX中?
- 请教一个stdfont对象如何复制?
- 在vb中怎么访问网络上的mdb文件?比如ftp://***.com/*.mdb
- VB+SQL Server做的程序如何打包?
- 怎样将查询到的记录保存到一个文本文件中??
- 请问如何用Winsock发送数据?
- 如何将JavaScript中的数组通过参数传递到VB的ocx控件
- 我用wise install 打包vb6的程序,可runtimes打不进去,请帮忙
- 如何识别操作系统是WIN XP?(新手,请多指教)
- 现在还有高手在吗,一个小小的MsflexGrid删除问题。
.........
if err then
msgbox "连接失败!",vbinformation
exit sub
end if 这样可以吗?
.....connect_error:
If con.State = adStateClosed Then
MsgBox "连接超时,无法连接数据库服务器"
End
End If
msgbox "成功"
else
msgbox "失敗"
end if
msgbox "成功"
end if
对所有可应用对象,说明其对象状态是打开或是关闭。对执行异步方法的 Recordset 对象,说明当前的对象状态是连接、执行或是获取。返回值返回下列常量之一的长整型值。常量 说明
AdStateClosed 默认,指示对象是关闭的。
AdStateOpen 指示对象是打开的。
AdStateConnecting 指示 Recordset 对象正在连接。
AdStateExecuting 指示 Recordset 对象正在执行命令。
AdStateFetching 指示 Recordset 对象的行正在被读取。
说明可以随时使用 State 属性确定指定对象的当前状态。该属性是只读的。Recordset 对象的 State 属性可以是组合值。例如,如果正在执行语句,该属性将是 adStateOpen 和 adStateExecuting 的组合值。
中的cnns是什么对象吗?以及adstateopen是否是个常数.
可以给出一个完整的程序吗? thank you!!!由于小弟是初学vb,可能问题有点.......请各位高手见谅.
Private Const ConStr = "provider=msdaora;data source=ts;user id=ts;password=ts"Public Sub connect_oracle()
On Error GoTo connect_error
Set oracle_con = New ADODB.Connection
With oracle_con
.CommandTimeout = 500
.ConnectionString = ConStr
.CursorLocation = adUseServer
.Open
End With
connect_error:
If oracle_con.State = adStateClosed Then
MsgBox "连接超时,无法连接数据库服务器"
End
End If
End Sub
这是我在模块里写的连接ORACLE的代码,希望对你有帮助!
db_err = ""
' set the connection string
Dim connect_str As String
connect_str = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=123;"
connect_str = connect_str & "Initial Catalog=pub;Data Source=192.168.11.120;Connect Timeout=30"
On Local Error GoTo connection_error
conn.Open connect_str
make_connection = True
Exit Function
connection_error:
db_err = "Connect fail !! " & Err.Description
make_connection = False
End Function