NO MORE CAREER
POLITICIANS!
Get Out Of Our House: Replacing congress with TRUE citizens!
Contact Doug!
Learn About Doug!
View Doug Boude's online resume
updated 11/18/2009

View Doug Boude's profile on LinkedIn
Link to me!

Follow Doug Boude on Twitter
Follow me!

Be Doug's friend on Facebook
Befriend me!
(I promise not to follow you home)
OO Lexicon
Chat with Doug!
Recent Entries
You may also be interested in...
Web Hosting

best web hosting - top web hosting sites, thetop10bestwebhosting.com

Czech your Page Rank!
Check Page Rank of any web site pages instantly:
This free page rank checking tool is powered by Page Rank Checker service
Surf's Up!
Visit Egosurf.org and massage YOUR web ego!
My Score: 9,001
Doug's Books

Read (and recommend)

  • Men are from Mars, Women are from Venus
  • The Wisdom of Crowds: Why the Many Are Smarter Than the Few and How Collective Wisdom Shapes Business, Economies, Societies and Nations
  • Blink: The Power of Thinking Without Thinking
  • Head First Design Patterns
  • Transact-SQL Programming
  • What's So Amazing About Grace?
  • Just So Stories (Rudyard Kipling collection)

Reading

  • Prayer: Does it Make Any Difference?
  • Data Mining (Practical Machine Learning Tools and Techniques)
<< September, 2010 >>
SMTWTFS
1234
567891011
12131415161718
19202122232425
2627282930
Search Blog

Recent Comments
Re: Railo 3.1 on Windows Server 2008 and IIS7 - Part 3 of 3 (by Jon at 8/27 2:04 PM)
Re: Hosts File Changes Not Acknowledged on Vista 64 (by Spacy at 8/24 3:46 PM)
Re: THE DAY CFUNITED DIED (by ComboFusion at 8/23 10:50 AM)
Re: My Grandpa (by Tasha at 8/10 4:29 PM)
Re: Just What IS a 'Service Layer', Anyway? (by dougboude at 8/02 10:10 AM)
Re: Just What IS a 'Service Layer', Anyway? (by Isaac at 8/02 2:25 AM)
Re: PayPal IPN Coldfusion CFC (by Soyestudiambre at 7/25 6:12 PM)
Re: PHP vs COLDFUSION (by Tony Garcia at 7/17 11:24 AM)
Re: PHP vs COLDFUSION (by dougboude at 7/14 8:45 AM)
Re: PHP vs COLDFUSION (by Lola LB at 7/14 5:51 AM)
Categories
Archives
Photo Albums
Funnies (5)
Family (3)
RSS

Powered by
BlogCFM v1.11

12 March 2009
Easy Way to Grab Remote SQL Data

Okay, this is just too cool so I thought I'd share it.

Let's say you have access to a database on a remote server somewhere, and there's data there that you would love to have a copy of locally. Options, options, options...well, if we aren't using SQL Express we have lots of options for migrating the data. But in our case, we ARE using SQL Express, so we don't have easy access to linking servers and other more advanced commands. Wouldn't it be just perfect then if we could simply do a SELECT * INTO MyNewLocalTable from [remote table]? Turns out that I CAN if I turn on an option that is turned off by default. So first, I execute these two lines in a query window (I'm using SQL Server Management Studio Express):

sp_configure 'Ad Hoc Distributed Queries', 1
RECONFIGURE

 

Then, I execute THIS query (well, one like it with suitable values substituted):

SELECT * INTO MYDATABASE.dbo.MyNewTable
FROM  OPENDATASOURCE(
   'SQLOLEDB',
   'Data Source=[url to remote server here, including port if needed];User ID=[sql username];Password=[sql password]'
   ).REMOTEDATABASE.dbo.SourceTable

 

Worked like a charm! Now I have a local copy of the remote data. In my case I migrated a little over 80,000 rows and it took about a minute or less. Saweeeet.

Doug out.




Posted by dougboude at 5:47 PM | PRINT THIS POST! |Link | 11 comments
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

Re: Easy Way to Grab Remote SQL Data
That's pretty cool! I've been enjoying reading your blog.
Posted by Donnetta on March 12, 2009 at 9:38 PM

Re: Easy Way to Grab Remote SQL Data
Very, very cool! Thanks!
Posted by Seth on March 12, 2009 at 11:41 PM

Re: Easy Way to Grab Remote SQL Data
Cool, I am going to check this out
Posted by John Gag on March 13, 2009 at 9:23 AM

Re: Easy Way to Grab Remote SQL Data
Hey Doug:

Any idea if there's an equivalent for MySQL..?
Posted by Jay on March 13, 2009 at 9:45 AM

Re: Easy Way to Grab Remote SQL Data
@jay - Not sure, Jay. I don't use MySQL much...but I wouldn't be at all surprised to find out there IS an equivalent function to OPENDATASOURCE. :)
Posted by dougboude on March 13, 2009 at 10:22 AM

Re: Easy Way to Grab Remote SQL Data
Doug, that's a pretty nifty trick indeed. It does scare me a bit though. Do you not have to turn on some server-side setting on the remote database in order to enable the feature? Even if someone has a valid username/password I'd want to have this setting turned off globally or only allow it for certain users. I have an awesome SQL Server DBA so I'll send him a link to your post and see what he says.

Also, your comment spam method - while probably very effective - is a bit of a pain. I'm not recommending you turn it off or anything, I just wanted to provide my feedback on it "just so you know." Cheers!
Posted by Aaron West on March 13, 2009 at 1:40 PM

Re: Easy Way to Grab Remote SQL Data
@Aaron - no, I did nothing at all on the remote server. In fact, the absolute ONLY access my user has is SELECT on a specific database, that's it. As tight as the admins are on the remote server, I'm SURE they didn't enable distributed queries on purpose. In fact, if they knew I did it, they'd probably find a way to block it asap. :)
Posted by dougboude on March 13, 2009 at 1:52 PM

Re: Easy Way to Grab Remote SQL Data
I really like South Park also. For some reason you have a disney banner ad under your recent rant. This is total insanity or pure genius, in an ironic way. Can you recommend the fastest way for a beginner to learn SQL express? Thanks, Phil
Posted by Phil on March 15, 2009 at 12:45 PM

Re: Easy Way to Grab Remote SQL Data
@phil - I'm gonna go with the "pure genius" choice on that one. :) Actually, I have google ads inserted there, and it selects ads based on content. But I do love the irony of it as well.

as far as learning sql express...do you mean learning how to write queries, create tables, use the admin interface, or what? Of course, the best way to learn anything is to just jump in and play with it, which is what i always recommend. Think up a small project you want to create, then attempt to build it, using Google and your peer network (which you can include me in) to ask questions of as you go and can't figure things out. By the time you get it working like you want, you will have learned a WHOLE lot!
Posted by dougboude on March 15, 2009 at 2:18 PM

Re: Easy Way to Grab Remote SQL Data
I get an error when I try to execute the first RECONFIGRE part in SQL Express. It says the 'Ad Hoc Distributed Queries' is not a valid option or might be an advanced option.

Any Ideas?

The reason I want to do this is because we get provided a view on a remote server (which does not belong to us), so I want to JOIN OPENROWSET from the view with local data from our database.

But I get a No Login-mapping Exists error. I cannot create a linked server because we use Express and the remote data does not belong to us. Any help would be greatly appreciated!
Posted by Jonathan on June 1, 2009 at 2:53 AM

Re: Easy Way to Grab Remote SQL Data
That's pretty awesome... I wish I knew about this a few weeks ago! Still very handy to know.
Posted by Philip on June 28, 2010 at 8:37 PM

Name:   Required
Email:   Required your email address will not be publicly displayed.

Want to receive notifications when new comments are added? Login/Register for an account.

Time to take the Turing Test!!!

8 plus 14 equals
Type in the answer to the question you see above:

Your comment:

Sorry, no HTML allowed!