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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VBA, Export Table from one SQL Server to a different SQL Server

Status
Not open for further replies.

kjv1611

New member
Jul 9, 2003
10,758
US
Is it possible, Using VBA, to export a table from one SQL Server to another SQL Server, without the data ever being pulled into Access?

This may not be possible, but thought I'd ask. Any thoughts, references, suggestions?

Thanks,
 
Well... right off the bat...

I would recommend setting up a SSIS ETL Process to transfer the data. You can set a flag in a control table that is checked every few minutes by a job, and it the flag is found the Job will start the ETL Process (SSIS formerly DTS)... then delete the flag from the table.

Another approach is to use a SQL Server Stored Procedure that will simply execute a few TSQL commands...
- Trauncate Target Table
- Select * INTO Target Table from Source Table

And, if really needed you can execute the TSQL commands above directly from MS Access via ADO Calls in VBA Code provided you have the necessary SQL Server Permissions and ADO connection set up.

I hope this was helpful...



Steve Medvid
IT Consultant & Web Master
 
Thanks for the thoughts. I'll look into those. I'm afraid I may not have appropriate permissions. Of course, I could get those permissions, if that ends up being best and gets approved, but I'm really hoping to get this setup for someone else.. and they may not then have the right permissions. So, I'll look, but may end up just leaving this part manual, and automate the rest... I'll keep thinking though, and looking... Thanks for the suggestions. I'll post back and let you know what if any of that I can use..

Thanks as well for any other thoughts or suggestions..
 
Alright, I sorted out a solution. I'll basically be using passthrough queries via VBA to do the work. The servers have a connection between them already, so I can just do straight queries.

What I'll do is use Chunking to keep from overloading the connection, since the recordset is currently at 150k records and growing - only 5 or 6 columns, but still 150k records. That's not super terrible, but I'll chunk it just to make sure no issues arise.

So it'll be like this:

--If the table exists on the "to" server, then drop it.
--create the table on the "to" server.
--Insert into the "to" server table, Select * from the "from" from server table, chunked sets..

I tested it with 1,000 rows and it worked perfectly.

What I'll have is a couple of passthrough query objects set up, and I'll modify the SQL of those objects for each step, run, and move on to the next step afterwards.

[bigglasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top