hatman
Well-known Member
- Joined
- Apr 8, 2005
- Messages
- 2,664
I have successfully joined local Worksheet data with sqlServer tables using the following syntax:
To simplify parsing out syntax, I have also run this "version" to confirm that the connection works before attempting the join:
This simplified version werx fine with sqlServer. However, when I instead use an Oracle connection string, I get one of (2) error messages depending upon whether I use a TNS string or a so-called TNS-less string. One tells me the table cannot be modified because it is readonly, and the other tells me that JET cannot find the table.
I confirmed that the (2) Oracle connection strings "work" by simply connecting to Oracle only with the following syntax:
Through trial and error, and a lot of help from ConnectionStrings.com, I finally narrowed down to the following connections strings that work:
(where I substitute OraHome10g instead of OraHome92 to reflect the version we use here.)
and
For kix, I tried putting in gibberish for SID and UserID and PWD to see if I could get any other error messages to be returned. Interestingly, no matter what I change in the connection string, each Driver/Provider seems to simply output a useless error message that doesn;t really describe what the true failure is.
My Plan B is to simply iterate through the records of my worksheet and perform an SQL query of Oracle for each record and append the results into the worksheet. It's messy but do-able. However, I would LOVE IT if anyone can look at what I am doing and tell me how to make Plan A work as it is by far the most elegant solution.
Rich (BB code):
Set objConnection = New ADODB.Connection
Set objRecordset = New ADODB.Recordset
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.FullName & _
";Extended Properties=""Excel 8.0;HDR=Yes;"";"
SQL = "SELECT * FROM [Sheet1$] l INNER JOIN [sqlServer_Conn_String].TableName r ON l.wsField = r.serverField"
objRecordset.Open sql, objConnection, adOpenDynamic, adLockReadOnly, adCmdText
To simplify parsing out syntax, I have also run this "version" to confirm that the connection works before attempting the join:
Rich (BB code):
Set objConnection = New ADODB.Connection
Set objRecordset = New ADODB.Recordset
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.FullName & _
";Extended Properties=""Excel 8.0;HDR=Yes;"";"
SQL = "SELECT * [sqlServer_Conn_String].TableName"
objRecordset.Open sql, objConnection, adOpenDynamic, adLockReadOnly, adCmdText
This simplified version werx fine with sqlServer. However, when I instead use an Oracle connection string, I get one of (2) error messages depending upon whether I use a TNS string or a so-called TNS-less string. One tells me the table cannot be modified because it is readonly, and the other tells me that JET cannot find the table.
I confirmed that the (2) Oracle connection strings "work" by simply connecting to Oracle only with the following syntax:
Rich (BB code):
Set objConnection = New ADODB.Connection
Set objRecordset = New ADODB.Recordset
objConnection.Open "Oracle_Connection_String"
SQL = "SELECT * FROM TableName"
objRecordset.Open sql, objConnection, adOpenDynamic, adLockReadOnly, adCmdText
Through trial and error, and a lot of help from ConnectionStrings.com, I finally narrowed down to the following connections strings that work:
Rich (BB code):
Driver={Oracle in OraHome92};Dbq=myTNSServiceName;Uid=myUsername;Pwd=myPassword;
and
Rich (BB code):
Provider=OraOLEDB.Oracle;
Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myHost)(PORT=myPort)))(CONNECT_DATA=(SID=MyOracleSID)(SERVER=DEDICATED)));
User Id=myUsername;Password=myPassword;
For kix, I tried putting in gibberish for SID and UserID and PWD to see if I could get any other error messages to be returned. Interestingly, no matter what I change in the connection string, each Driver/Provider seems to simply output a useless error message that doesn;t really describe what the true failure is.
My Plan B is to simply iterate through the records of my worksheet and perform an SQL query of Oracle for each record and append the results into the worksheet. It's messy but do-able. However, I would LOVE IT if anyone can look at what I am doing and tell me how to make Plan A work as it is by far the most elegant solution.