Copy a file to target server when deploying

Can't work out how to do this, can anyone give some tips?

I have a dataabse project in Visual Studio 2010. The project includes a CSV file. I intend to import this CSV file at deploy time in the post-deployment script via something like

BULK INSERT table FROM '$(DefaultLogPath)\Data.csv'

but I can't find out how to copy the file to the DefaultLogPath.

more ▼

asked Jun 24, 2011 at 02:20 AM in Default

avatar image

905 60 64 68

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Take a look at the pre and post deployment tasks. You should be able to put in a command line copy statement, or even a powershell call, from there.

more ▼

answered Jun 24, 2011 at 03:36 AM

avatar image

Grant Fritchey ♦♦
137k 20 46 81

That's what I was thinking. But I need to reference both the source path and the destination path, which will be a UNC folder on the target SQL server. How do I reference the target SQL server name from within a post-deploy task?

Jun 24, 2011 at 03:40 AM xnl28

Hmmm... Have you tried using the server name variable? If not, then you might want to go a little more old school. Build a batch file that calls the command line for deployments, passing in your server name and then uses that same information to perform the file copy. We had to do that for a lot of our deployments.

Jun 24, 2011 at 04:04 AM Grant Fritchey ♦♦

How do I reference the server name variable from within the post-build event command line?

Jun 24, 2011 at 04:14 AM xnl28

Oooh, I knew you'd ask that. I don't have VS installed currently to look it up. Look at the properties for the project and then find the tab that has the variables on it. You'll see the exact syntax. It's something like %%server_name%%.

Jun 24, 2011 at 05:05 AM Grant Fritchey ♦♦

I don't see anything like %%server_name%% in the macros available for the post-build events in the Build Events tab. These are the macros I see there

$(CatalogPropertiesFile) $(Configuration) $(DefaultLogin) $(DefaultSchema) $(DefaultUser) $(DeploymentConfigFile) $(DeployToDatabase) $(DeployToScript) $(DSP) $(FinalDeployScriptFile) $(FinalTargetConnectionString) $(FinalTargetDatabase) $(ModelCollation) $(OutputPath) $(ProjectDir) $(ProjectName) $(ServerPropertiesFile) $(SolutionDir) $(SolutionExt) $(SolutionFileName) $(SolutionName) $(SolutionPath) $(SqlCommandVariablesFile)

Jun 24, 2011 at 07:39 AM xnl28
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Jun 24, 2011 at 02:20 AM

Seen: 1618 times

Last Updated: Jun 24, 2011 at 02:20 AM

Copyright 2018 Redgate Software. Privacy Policy