go-oci8 DSN connection problem

422 views
Skip to first unread message

camero...@gmail.com

unread,
Oct 28, 2014, 9:40:45 AM10/28/14
to golan...@googlegroups.com
Hello,

I have go-oci8 set up in a windows 64 bit env.  I was hoping to connect to an Oracle database.  Trying to get all the tools set up for Oracle has been... a pain.  Lets not worry about "why" but the how.

When following the examples in go-oci8 I pass the connection: "username/password@host:1521/db" (as an example).

db, err := sql.Open("oci8", "username/password@host:1521/db")

This doesn't return an error, but when I try to query off of it, it errors, with no information. 

I noticed looking though some of the source that oci8 might be trying to get environment variables, specifically the DSN, which would be defined in tsnames.ora.  Is this what oci8 is trying to grab?  

A DSN would look something like:

db = 
(DESCRIPTION = 
(ADDRESS = (PROTOCOL = TCP)(HOST = host)(PORT = 1521)) 
(CONNECT_DATA = 
(SERVER = DEDICATED) 
(SERVICE_NAME = db.some.com

I can connect to this Oracle database with other programs in the same environment.  I have also set up my oci8.pc following https://gist.github.com/mnadel/8678269 .  Am I missing something trivial?  Please let me know if there is more information needed.  I'm close to pulling all my hair out.

brainman

unread,
Oct 28, 2014, 8:43:12 PM10/28/14
to golan...@googlegroups.com
On Wednesday, 29 October 2014 00:40:45 UTC+11, Cameron Boyer wrote:

> ... I can connect to this Oracle database with other programs in the same environment. ...

I don't know anything about oci8 package. And I have never used Oracle database. But, if you can connected to your database via ODBC, perhaps "code.google.com/p/odbc" package might work for you.

Alex

Tamás Gulácsi

unread,
Oct 29, 2014, 1:56:43 AM10/29/14
to golan...@googlegroups.com
Hi,

Oracle has some obscure legacy regarding connection to a database.
The easiest way is to just present it with all the required parameters: put all the things betwen () in the place of the "sid" part.
I don't know how go-oci8's ParseDSN will treat that, though.

The second possibility is to find out where should your tnsnames.ora be. Maybe try to set TNS_ADMIN env. var to its directory.

(A side note: set your NLS_LANG env to something.AL32UTF8 (i.e. american_america.AL32UTF8) if you connect to a database which is not AL32UTF8 - in Go you need UTF-8 strings)

A third possibility is to try my goracle driver [1] instead of go-oci8 - I know that accepts such connection strings at the "sid" part (user/passw@sid).
(This library sets the NLS_LANG env var for you, right before initializing the OCI lib - I've tried to convince Matt to do the same in go-oci8, but with no avail.)

[1]: github.com/tgulacsi/goracle/godrv
Reply all
Reply to author
Forward
0 new messages