Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In vba module - problems creating odbc connection string 1

Status
Not open for further replies.

notageek7

Technical User
Jan 23, 2004
54
0
0
US
Could someone with experience with using vba and oracle PLEASE HELP. I keep getting numerous errors when trying to open a connection to my oracle db from within a vba module. I'm including part of a function below that accesses an oracle db to retrieve the next value, because no autonumber. Unfortunately the connection never opens because of some error....sometimes saying 'no default driver' declared, or 'dsn not ...'. I seem to be missing something, but not sure what. I cut and pasted my connection string from a pass through query which uses an odbc connection to retrieve the next value from a chosen table. The query works but when using the same connection string in code I can't get it to work. Any ideas????






Function GetOracleAutoKey(psdTableName) As Long

Dim cnn As ADODB.Connection, rst As ADODB.Recordset
Dim sqlString As String, tempVal As Long

sqlString = "SELECT sfdccms_" & psdTableName & "_s.nextval AS NextKeyValue FROM dual;"

Set cnn = New ADODB.Connection
cnn.ConnectionString = "ODBC;DSN=CommissionsDb;UID=SFDCEIM;PWD=SFDCEIM;DBQ=DEVM;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;" & _
"FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;"

cnn.Open

Set rst = New ADODB.Recordset
rst.Open sqlString, cnn, adOpenKeyset, adLockPessimistic



End Function
 
Try for connection string something like this,

cnn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=dbname;User Id=admin;Password=pass;"

John Borges
 
thanks for your input cmmrfrds, i've already been to their site and tried the code below with no success.

oConn.Open "DSN=mySystemDSN;" & _
"Uid=myUsername;" & _
"Pwd=myPassword"
 
Thought this might work jbpez, but using the code below gives me an ... 'ORA-00911: invalid character' error....


Function tmpGetOracleAutoKey(psdTableName) As Long

Dim cnn As ADODB.Connection, rst As ADODB.Recordset
Dim sqlString As String, tempVal As Long

sqlString = "SELECT sfdceim.sfdccms_Draws_S.nextval AS NextKeyValue FROM dual;"

Set cnn = New ADODB.Connection

cnn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=Mosaics;User Id=SFDCEIM;Password=SFDCEIM;"

cnn.Open

Set rst = New ADODB.Recordset
rst.Open sqlString, cnn, adOpenKeyset, adLockPessimistic
 
Thank you very much jbpez, your suggestion worked with some tweeking of my code...it turns out the improper character that oracle dosn't like is the ';' on the end of the statement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top