mattn / go-oci8

Oracle driver for Go using database/sql
https://mattn.kaoriya.net/
MIT License
630 stars 212 forks source link

how set connect timeout? #352

Closed zhaoya881010 closed 5 years ago

zhaoya881010 commented 5 years ago

If set a error address, it will take a long time to return.how set connect timeout?

MichaelS11 commented 5 years ago

The test code shows a pretty good example, can change TestContextTimeout:

https://github.com/mattn/go-oci8/blob/63b1f03e8cae01d2edb7d15e86bde94e2fb55723/oci8Sql_test.go#L30-L50

If you use a tnsnames.ora file, add CONNECT_TIMEOUT. The tnsname goes inside the openString instead of host.

MYDBNAME =  
(DESCRIPTION =
  (CONNECT_TIMEOUT = 55)
  (ADDRESS = (PROTOCOL = TCP)(HOST = myhostname)(PORT = 1521))
)

Can also use a sqlnet.ora file instead and set SQLNET.OUTBOUND_CONNECT_TIMEOUT=55 in that file. https://docs.oracle.com/cd/E11882_01/network.112/e10835/sqlnet.htm#NETRF427

cjbj commented 5 years ago

You can now set some of these options via the Easy Connect syntax without needing a tnsnames.ora or sqlnet.ora. See https://docs.oracle.com/en/database/oracle/oracle-database/19/netag/configuring-naming-methods.html#GUID-8C85D289-6AF3-41BC-848B-BF39D32648BA

zhaoya881010 commented 5 years ago

@cjbj i test use Easy Connect. command="system/oracle@host:1521/ora11g?connect_timeout=60&retry_count=1"

sql.Open() dp.ping()

i found timeout always "20s".

zhaoya881010 commented 5 years ago

easy connect is oracle 19,i am 11.

cjbj commented 5 years ago

Small correction: Easy Connect came in Oracle DB 10. Easy Connect Plus came in Oracle DB 19.

MichaelS11 commented 5 years ago

I do not think oci8 supports Easy Connect at this time. Feature request for that is probably needed.

MichaelS11 commented 5 years ago

@zhaoya881010 Did the tnsnames.ora or sqlnet.ora file change work fine?

MichaelS11 commented 5 years ago

@mattn Close this?