VB連線oracle資料庫

2021-09-11 05:43:49 字數 3363 閱讀 5383

做個人用小工具,而不是頻繁交易的大專案,下面兩種連線都可以(各自需要相關驅動):

注:還有其它連線方式,對比後放棄了。不需要安裝oracle客戶端。環境變數需要配置。

public function getconndb() as integer

on error goto errflag

getconndb = fail

dim tmpstr as string

if g_conn.state <> 0 then

tmpstr = "already connect at " & date & " " & time & ""

call writelog(tmpstr)

getconndb = success

exit function

'g_conn.close

end if

'dbconnect.provider = "msadora"

'dbconnect.connectionstring = "provider=msdaora;data source=slbps;user id=***" '--

g_conn.connectionstring = "driver=;data source=slbps;user id=***;pwd=***"

g_conn.open

getconndb = success

tmpstr = "getconndb connect to slbps106 success at " & date & " " & time & ""

call writelog(tmpstr)

exit function

errflag:

if err.number <> 0 then

msgbox "errno" & err.number & ":" & err.description

exit function

end if

end function

'連線方式說明:

'1. connectionstring = "provider=oraoledb.oracle;persist security info=false;user id=username;data source=database;extended properties='';password=password"

private sub cmd_odbc_conn_click()

'driver=;

on error goto errflag

dim dbconnect as new adodb.connection

dim tmpconnstring as string

'dbconnect.provider = "msadora"

'dbconnect.connectionstring = "provider=msdaora;data source=slbps;user id=***" '--

'dbconnect.connectionstring = "driver=;data source=slbps;user id=***;pwd=***" '測試環境可用。

'dbconnect.open "filedsn=d:\toracleconn\myvbdemo\conf\dsn\***slbps.dsn"

dim tmpsss as string * 50

'tmpsss = "filedsn=d:\toracleconn\myvbdemo\conf\dsn\***slbps.dsn"

'dbconnect.open

'tmpsss = fg_setstring(tmpsss)

'dbconnect.open tmpsss

if dbconnect.state <> adstateclosed then '0 adstateclosed

dbconnect.close

end if

dbconnect.open

msgbox "conn success"

dbconnect.close

set dbconnect = nothing

exit sub

errflag:

if err.number <> 0 then

msgbox "errno" & err.number & ":" & err.description

exit sub

end if

set dbconnect = nothing

end sub

private sub cmd_oledb_conn_click()

on error goto toexit

oradb_open = false

'set oradb = new adodb.connection

dim oradb as new adodb.connection

connectionstring = "provider=oraoledb.oracle;password=***;user id=***;data source=(description =(address_list=(address=(protocol=tcp)(host=xx.xx.xx.xx)(port=1521)))(connect_data=(service_name=slbps)));persist security info=true"

'connectionstring = "provider=oraoledb.oracle;password=cygck;user id=cygck;data source=""(description =(address_list=(address=(protocol=tcp)(host=***.***.***.***)(port=1521)))(connect_data=(service_name=ora9i)))"";persist security info=true"

'oradb.cursorlocation = aduseserver

oradb.open connectionstring

oradb_open = true

msgbox "conn success"

set oradb = nothing

exit sub

toexit:

msgbox "連線資料庫伺服器錯誤,您可以在網路正常後繼續使用。", vbinformation, "錯誤資訊"

msgbox "errno=" & err.number & err.description

msgbox connectionstring

set oradb = nothing

oradb_open = false

end sub

it』s over.

2019-02-22

VB連線ORACLE資料庫

開啟資料庫 public sub openoradb on error goto toexit oradb open false set oradb new adodb.connection oraconstr provider oraoledb.oracle.1 password strorapw...

VB連線遠端Oracle資料庫

1 instantclient basic windows.x64 11.2.0.4.0.zip和instantclient odbc windows.x64 11.2.0.4.0.zip 2.解壓兩個檔案到同乙個資料夾 instantclient 11 2 3.雙擊或者用命令列安裝 odbc in...

VB與資料庫 資料庫連線

話說學生管理系統和機房收費系統都完成了,再回來說資料庫的連線真的好嗎?貌似不太好,但是誰讓自己欠賬了呢 除了還,還能有更好的解決方法嗎?前幾天說 紅皮書 中的七個物件。當時的反應哪七個,腦子完全一片空白,不知所云。所以找出來,再看看吧。vb6.0與sqlserver有源資料庫連線,vb6.0中資料訪...