x

how do I code path name to a server in a variable in SSIS package

I'm trying to code the server path name in a variable for my flat file destination connection manager so it's easier to change. I don't know whether to put one backslash or two.

I've tried both and get the same error "Attempt to parse the expression "\server\folder" failed. The token "" at line number "0", character number "0" was not recognized.

The string variable contains. \server\folder\ I'm combining this with the file name also stored in a variable.
more ▼

asked Dec 01 '11 at 02:25 PM in Default

Dave__C gravatar image

Dave__C
23 1 1 2

This worked. I appreciate the advice.
Dec 02 '11 at 12:35 PM Dave__C
(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

You need to put double the amount of backslashes. an easy way to test this is to click on the variable, go to the properties window and click on the ellipses in the espression property.

Then type in "\\\\servername\\c$", and click on Evaluate Expression and it will show it as \\servername\c$

EDIT: Backslashes don't work well, there are 4 at the start and 2 in the middle.
more ▼

answered Dec 01 '11 at 06:44 PM

Daniel Ross gravatar image

Daniel Ross
2.9k 10 12 13

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

Backslashes work well for me. Here is a sample expression I use to generate a filename that starts with "Test_" and ends with today date to UNC file server destination in one of my SSIS packages:

"\\\\fileserver\\Test_" + SUBSTRING( (DT_WSTR,30)GETDATE() , 1, 4 ) + SUBSTRING ( (DT_WSTR,30)GETDATE() , 6, 2 )  + SUBSTRING( (DT_WSTR,30)GETDATE() , 9, 2 )  + ".txt"

When evaluated the above expression returns(today) \\fileserver\Test_20111205.txt

So in your case you should use:

"\\\\ServerName\\c$\\Test_" + SUBSTRING( (DT_WSTR,30)GETDATE() , 1, 4 ) + SUBSTRING ( (DT_WSTR,30)GETDATE() , 6, 2 )  + SUBSTRING( (DT_WSTR,30)GETDATE() , 9, 2 )  + ".txt"

which gives \\ServerName\c$\Test_20111205.txt when evaluated.

more ▼

answered Dec 05 '11 at 12:24 PM

DaniSQL gravatar image

DaniSQL
4.9k 33 35 39

(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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

SQL Server Central

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

Topics:

x897
x26

asked: Dec 01 '11 at 02:25 PM

Seen: 2133 times

Last Updated: Dec 01 '11 at 02:25 PM