Solved

sql to access file in different server

Posted on 2014-09-25
6
120 Views
Last Modified: 2014-10-06
Hi,

I have a test file in server A and my DB server is in server B.
Now I want to write query in SSMS from Server B and that query should access the file from server A and parse it to store the data in DB.

I am not sure how to establish the connection to server B and get that file.
I am trying to write a stored procedure for this.
No I should not copy that file.

So any suggestions how to get that file from server B to DB server A.

Thanks,
0
Comment
Question by:shragi
6 Comments
 
LVL 3

Assisted Solution

by:Matthew Borrusso
Matthew Borrusso earned 250 total points
Comment Utility
You need to write the query to import, say CSV from a network location.

if this is batch-able, you may want to do something like xcopy \\server1\data.csv d:\temp or whatever.

schedule this transfer to occur in conjunction with your export. Say 6 am export data from whatever to this CSV, 7am perform the batch to xcopy the data to the server. then 8 pm schedule your query to import the csv accordingly..

Times would be your gig.. Granted, this is not the cleanest way to do it, but if you have to import/export, this might just be an easy way if you cannot just create a connector and directly transfer the data table to table.
0
 
LVL 3

Expert Comment

by:Matthew Borrusso
Comment Utility
Again, I just want to say, I know its not clean.. but it should work given limited options.
0
 

Author Comment

by:shragi
Comment Utility
does this command removes the file from original server B
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:Matthew Borrusso
Comment Utility
you can add a delete command to be run later. say 10am, or just set the commands to constantly overwrite the file names.
your call..

it just depends on how you want to do this.
0
 
LVL 11

Accepted Solution

by:
John_Vidmar earned 250 total points
Comment Utility
Use SQL Server Integration Services (SSIS) to read the file in it's original location, perform data transformations (if required), and store the data in SQL Server.  SSIS can also do other non-database tasks, like move/copy/delete/rename files.
0
 
LVL 45

Expert Comment

by:Vitor Montalvão
Comment Utility
If the idea it's to import data from a file to a table SSMS already provide this functionality.
Just right-click over the database name, choose Tasks / Import data... and follow the wizard.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now