PDA

View Full Version : Problem connecting to Oracle from MS Word



ftm
05-27-2009, 09:34 AM
I'm using MS Word 2007 on Vista and I'm getting an error of 'Run-time error '3706' Provider can not be found. It may not be installed properly' when I try to connect to an Oracle database to retrieve some data. The code is below, the error occurs at the line marked with the triple asterisk. I'm not sure what I've missed. I ensured that in VBE / Tools / References the Microsoft ActiveX Data Objects 2.8 Library reference is ticked. The TNS names database name, usename and password work with other applications eg. SQL*Plus. Any help would be much appreciated.

Function DbConnect() As Boolean
' Connect to Oracle database as lnb

Dim lnbConnection As ADODB.Connection
Dim ConnString As String ' Connection String
Const DatabaseName As String = "SIDTEST.KPORA2" ' Name of database
Const lnbUsername As String = "LNB" ' Name of user
Const lnbPassword As String = "#####" ' Password for LNB

' Create connection string
ConnString = "Provider=MSDORA.1;Password=" & lnbPassword & ";user id=" & lnbUsername & ";Data Source=" & DatabaseName

' Open a connection to the database
Set lnbConnection = New ADODB.Connection
With lnbConnection
.Open ConnString '*** error occurs here!!
If .State <> adStateOpen Then
MsgBox "Could not connect to database", vbOKOnly + vbExclamation, "Database connection error!"
DbConnect = False
Else
DbConnect = True
End If
End With

End Function

ftm
05-28-2009, 12:17 AM
In case anybody else gets this same error. I've now solved it. The connection string wasn't correct and I had missed out a letter 'A'.

Should have been...

"Provider=MSDAORA.1;Password=" & lnbPassword & ";user id=" & lnbUsername & ";Data Source=" & DatabaseName