Do not use on any
shared computer
September 8, 2008 10:00am pdt
 
[x]
Attachment Details

Copy table from Oracle  to Access db

Tags: Microsoft, Access, 2003, Oracle Provider for OLE DB 11.1.0.6.20, VBA
Hi, I'm hoping someone can help me with copying a table from a corporate Oracle database to an Access 2003 database on a file server.  I've installed the Oracle OLEDB Provider and Instant Client (the MS version couldn't detect the Oracle client).  Using a data link file I've tested my connection to the Oracle 10g server successfully.  I've also been able to retrieve an ADO recordset using the data link file and SELECT parameters successfully, so I know I am using the correct table names and connecting to the Oracle database correctly.

However, for performance reasons I would like to avoid looping through a recordset to copy the Oracle data to my local Access copy as this is painfully slow for large datasets.  I've attempted to use an "INSERT TO" SQL statement using an ADO command object.  I have unfortunately been unsuccessful thus far.  Although I've added an error trap to my test code to capture any ADO or VBA errors, the code never produces any errors when I run it.  It also never inserts any data into the tvwLOCATIONS table I am trying to populate.

I've copied the code Im using below.  I believe my problem may stem from the syntax used to specify the connection to the local Access db in the INSERT TO statement.  Please help me identify what I am doing incorrectly and how to perform the INSERT correctly.

Thanks!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
Public Sub testInsert()
 
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim lngAffected As Integer
Dim errADO As ADODB.Error
Dim strSQL As String
Dim strAccessDB As String
 
On Error GoTo HandleErrors
 
strAccessDB = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=G:\Common\Database\DC Database.mdb;"
 
strSQL = "INSERT INTO [" & strAccessDB & "].tvwLOCATIONS " & _
    "SELECT * " & _
    "FROM LOCATIONS " & _
    "WHERE CITY = 'Chicago'"
    
Debug.Print strSQL
 
Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
 
cnn.Open "File Name=C:\DBLINK.UDL"
'Debug.Print cnn.ConnectionString
 
'   Use this connection when connecting to Oracle dB
cmd.ActiveConnection = cnn
 
 
'   Set the properties of the command
cmd.CommandType = adCmdText
cmd.CommandText = strSQL
Debug.Print (cmd.ActiveConnection.ConnectionString)
 
'   Execute the command
cmd.Execute lngAffected
Debug.Print lngAffected & " Records modified"
 
Set cmd = Nothing
cnn.Close
Set cnn = Nothing
 
ExitHere:
    Exit Sub
    
HandleErrors:
    ' Check ADO Errors collection for contents
    With cnn
        If .Errors.Count > 0 Then
            For Each errADO In cnn.Errors
                Debug.Print "ADO:", errADO.Number, _
                 errADO.Description
            Next
        Else
            Debug.Print "VBA: ", Err.Number, _
                Err.Description
        End If
    End With
    Resume ExitHere
 
End Sub
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Software
Question Asked By: mahcel
Solution Provided By: MikeToole
Participating Experts: 1
Solution Grade: A
Views: 119
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by MikeToole

Rank: Guru

Expert Comment by MikeToole:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by mahcel
Author Comment by mahcel:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by MikeToole

Rank: Guru

Expert Comment by MikeToole:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by mahcel
Author Comment by mahcel:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by mahcel
Author Comment by mahcel:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by MikeToole

Rank: Guru

Expert Comment by MikeToole:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by mahcel
Author Comment by mahcel:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by MikeToole

Rank: Guru

Expert Comment by MikeToole:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by mahcel
Author Comment by mahcel:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by MikeToole

Rank: Guru

Accepted Solution by MikeToole:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628