Showing posts with label path. Show all posts
Showing posts with label path. Show all posts

Wednesday, March 21, 2012

FILENAME option in CREATE DATABASE statement

Hi,

I have a problem with CREATE DATABASE statement, since it needs to specify the absolut path for a file in the FILENAME= option. I would need instead a relative path, i.e. only the name of the file because the script that launch this SQL command is dependant on the installation path decided by the user, during the installation.
Is there a way to pass to the FILENAME only the name of the file?
Hope to have been clear :-)

Thanks in advanceTry KB article 307283:How To Create a SQL Server Database Programmatically by Using ADO.NET and Visual C# .NET

Terri|||Hi, Terry

I have created a batch file that run the script sql for the creating the database, but in the option FILENAME if the path does not exist on the clients PC - the script will fail.

Any suggestions appreciated.
Thanks.
Fabio.|||I'm really sorry, I missed the "relative path" part of your question. As far as I know SQL Server cannot use a relative path for the filename.

I wonder if you could make use of one of the system or extended stored procedures sp_helpfile, master..xp_getfiledetails, sp_helpdevice?? Or perhaps use the undocumented stored procedure XP_REGREAD to read the installation path out of the registry?

Terri|||Hello,

I have exactly the same question.

I've got a ASP.NET application, where I want to automate the creation of the database for the Webmaster (once they fill in the appropriate SQL Server/MSDE Database Server location and login info, etc...).

My dynamically written CREATE DATABASE script wants a full absolute filepath for the Data and Log files.

And obviously I need to take into account the fact the Database Server may not be local to the Webserver.

I can't seem to find any easy way to find this information, other than to do a query of the "Master" database, like so:

--------
USE [Master]
SELECT filename
FROM sysfiles
WHERE (name = 'master')
--------

The above returns a value like "C:\Data\MSSQL\data\master.mdf".

From this I could easily extract just the directory path portion.

Am I crazy? Is this reliable?

Or is there a better way to get this information?

Any insight would be appreciated....

fileLen function in stored procedure

Heres an extract of a stored procedure creating a column.
Path = FileLen([CacheServers].[CachePath]+
(left([DOCUMENT]. [PHYSICAL_DOC_GUID],6))+''''+[DOCUMENT]
.[PHYSICAL_DOC_GUID]+[DOCUMENT].[FileType])
Reult:
\\comp-ap- 70c\Imxxs$\data\docs\70393C\70393CE0EC6D
11D8BB64000D568A4637.tif
The above is a file path of an image stored on the SAN server. The code
above works perfectly fine in MS Access but not in SQL server 2K
It should return the size in bytes of the file.
Books online state the VBA function fileLen() works in SQL Analyser,
however, when I execute the stored procedure I receive an error message
"FileLen is not a recognised function name".
I cant find a thing on the Microsoft Tech communities the specifically
relates to calling VBA functions in SQL.
Any ideas?
Learning SQL and AccessIs there something wrong with the LEN function? Or DATALENGTH?
MC
"sebastian stephenson" <sebastianstephenson@.discussions.microsoft.com> wrote
in message news:E9F88AB0-05A3-4BE6-9EB0-6314A7685359@.microsoft.com...
> Heres an extract of a stored procedure creating a column.
> Path = FileLen([CacheServers].[CachePath]+
> (left([DOCUMENT]. [PHYSICAL_DOC_GUID],6))+''''+[DOCUMENT]
.[PHYSICAL_DOC_GUID]+[DOCUMENT].[FileType])
> Reult:
> \\comp-ap- 70c\Imxxs$\data\docs\70393C\70393CE0EC6D
11D8BB64000D568A4637.tif
> The above is a file path of an image stored on the SAN server. The code
> above works perfectly fine in MS Access but not in SQL server 2K
> It should return the size in bytes of the file.
> Books online state the VBA function fileLen() works in SQL Analyser,
> however, when I execute the stored procedure I receive an error message
> "FileLen is not a recognised function name".
> I cant find a thing on the Microsoft Tech communities the specifically
> relates to calling VBA functions in SQL.
> Any ideas?
> --
> Learning SQL and Access|||> Books online state the VBA function fileLen() works in SQL Analyser,
> however, when I execute the stored procedure I receive an error message
Where does it say that?
If you really need to check for file sizes from T-SQL you should look at the
sp_OA* system procedures. I'd suggest using an appropriate client applicatio
n
to supply the values to the server.
ML
http://milambda.blogspot.com/|||I obviously didnt understand you correctly. Is SQL Server 2005 an option?
You could use CLR for something like this.
MC
"MC" <marko_culo#@.#yahoo#.#com#> wrote in message
news:u%23FgSFLVGHA.524@.TK2MSFTNGP10.phx.gbl...
> Is there something wrong with the LEN function? Or DATALENGTH?
>
> MC
>
> "sebastian stephenson" <sebastianstephenson@.discussions.microsoft.com>
> wrote in message
> news:E9F88AB0-05A3-4BE6-9EB0-6314A7685359@.microsoft.com...
>

Wednesday, March 7, 2012

File Task Moving with variables...

I have a 'file system task' moving files from one server to another for processing. I have defined the path and filename as separate variables. When I attempt to pass them together into the task I receive an error.

Source Path & Filename:

@.[User:: DataSourceFolder]+"\\"+ @.[User::CD_PaidClaimSource]

Outputs:

\\umrdwh2\FTP\CLAIMDAILY.DATA

Destination Path Now: (Filename not specified per another thread.)

@.[User::WorkingFolder]

Original Destination Path: (Which did not work.)

@.[User::WorkingFolder]+"\\"+ @.[User::CD_PaidClaimSource]

I receive validation errors:

Error 1 Validation error. CLAIMDAILY Move : Failed to lock variable "\\umrdwh2\FTP\CLAIMDAILY.DATA" for read access with error 0xC0010001 "The variable cannot be found. This occurs when an attempt is made to retrieve a variable from the Variables collection on a container during execution of the package, and the variable is not there. The variable name may have changed or the variable is not being created.". ClaimLoading_MASTER.dtsx 0 0

How do I overcome this without hard coding the path in the task?


You should be editing the file connection managers (source and destination) via variable expressions, not the file system task, I believe.|||

CaptainMyCaptain wrote:

Error 1 Validation error. CLAIMDAILY Move : Failed to lock variable "\\umrdwh2\FTP\CLAIMDAILY.DATA" for read access with error 0xC0010001 "The variable cannot be found. This occurs when an attempt is made to retrieve a variable from the Variables collection on a container during execution of the package, and the variable is not there. The variable name may have changed or the variable is not being created.". ClaimLoading_MASTER.dtsx 0 0

That error is showing you the value of your variable, not it's name. Not sure how that could have happened, but hopefully it helps you figure out what is wrong.
|||

JayH wrote:

CaptainMyCaptain wrote:

Error 1 Validation error. CLAIMDAILY Move : Failed to lock variable "\\umrdwh2\FTP\CLAIMDAILY.DATA" for read access with error 0xC0010001 "The variable cannot be found. This occurs when an attempt is made to retrieve a variable from the Variables collection on a container during execution of the package, and the variable is not there. The variable name may have changed or the variable is not being created.". ClaimLoading_MASTER.dtsx 0 0

That error is showing you the value of your variable, not it's name. Not sure how that could have happened, but hopefully it helps you figure out what is wrong.

Oh, I think I get it. Did you specify that expression as the Source Path in the File System Task? I didn't think the UI allowed that. If so, you need to create a new variable, set it EvaluateAsExpression=true and put the expression there. Then reference that variable from your File System Task's SourceVariable property.
|||An example to illustrate what we're saying:

http://www.ssistalk.com/file_system_task.jpg|||

The picture helped immensely, thank you. I was trying to establish the source and destination on the expressions screen as well as the general screen which was causing some of the error. Once I removed the destination and source from the expressions screen it worked better.

I am having another issue now, however. Following the syntax in the picture exactly I am getting an error because the filename is being considered a part of the folder path in addition to the filename. I have as an expression:

My expression (like your picture):

"\\\\Apsw9026g1\\Admin\\Logs\\CLAIMDAILY.DATA"

Which outputs:

\\Apsw9026g1\Admin\Logs\CLAIMDAILY.DATA

But this is the error on execution:

Information: 0xC002F30E at CLAIMDAILY Move, File System Task: File or directory "\\Apsw9026g1\Admin\Logs\CLAIMDAILY.DATA\CLAIMDAILY.DATA" was deleted.

Error: 0xC002F304 at CLAIMDAILY Move, File System Task: An error occurred with the following error message: "Could not find a part of the path '\\Apsw9026g1\Admin\Logs\CLAIMDAILY.DATA\CLAIMDAILY.DATA'.".

Why is it duplicating the filename as part of the path? Did I miss a setting?

Roger

|||Try deleting the file system task and starting over.|||

Deleting everything variable, task, container, etc and recreating all of it results in the same error. Ideas? The funny part is the system loves the 'Source'; there are no errors, and it is the same syntax. It is only the 'destination' that is having trouble.

Rog

|||

CaptainMyCaptain wrote:

The picture helped immensely, thank you. I was trying to establish the source and destination on the expressions screen as well as the general screen which was causing some of the error. Once I removed the destination and source from the expressions screen it worked better.

I am having another issue now, however. Following the syntax in the picture exactly I am getting an error because the filename is being considered a part of the folder path in addition to the filename. I have as an expression:

My expression (like your picture):

"\\\\Apsw9026g1\\Admin\\Logs\\CLAIMDAILY.DATA"

Which outputs:

\\Apsw9026g1\Admin\Logs\CLAIMDAILY.DATA

But this is the error on execution:

Information: 0xC002F30E at CLAIMDAILY Move, File System Task: File or directory "\\Apsw9026g1\Admin\Logs\CLAIMDAILY.DATA\CLAIMDAILY.DATA" was deleted.

Error: 0xC002F304 at CLAIMDAILY Move, File System Task: An error occurred with the following error message: "Could not find a part of the path '\\Apsw9026g1\Admin\Logs\CLAIMDAILY.DATA\CLAIMDAILY.DATA'.".

Why is it duplicating the filename as part of the path? Did I miss a setting?

Roger

Roger,

I have an example that uses the file system task to move/rename files in case you are interested: http://rafael-salas.blogspot.com/2007/03/ssis-file-system-task-move-and-rename.html

If I recall correctly, when using variables in the file system task, IsDestiantionPathVariable and IsSourcePathVarible, and depending on the operation used; some times the task expect only the path that points to the file and some times it expects the path AND the file name. In your case it looks like it only expects the path; so remove the file name from the expression. Do not assume both variables need path and file name.

|||

That was the answer. Thank you all for helping this greenhorn to get his job done!

Roger

File System Task - relative location ?

hi,

I am using "File System Task" to copy files from one pre-defined location to another.

Is there a way to provide a "relative path" for the corresponding connections? If yes, how to set it up for deployment?

If not, I guess the option will be to update the "connection string" property for the file connections using package configurations.

thanks,
NiteshAnother option is to store the "root" location in a folder (it can be populated from a configuration) and you can then use property expressions on your file connection manager connection strings to use that variable.

-Jamie

File System Task - Move File with Dynamic Destination Path

I am having an issue with the File System Task.

I was wondering if there is a way to 'Move File' with the File System Task inside of a For Each Loop container but to dynamically set the Destination path variable.

Currently, this is what I have:

FileDestinationPath variable - set to C:\TestFiles

FileSourcePath variable - set to C:\TestFiles

FileNameAndLocation variable - set to blank

For Each Loop Container – Iterates through a folder C:\TestFiles that has .txt files in it with dates in the file name. Ex: Test_09142006.txt. Sets the file path (fully qualified) to the Variable Mapping FileNameAndLocation.

Script Task (within For Each Loop, first step) – Sets the FileDestinationPath to the correct dated folder within C:\TestFiles. For example, if the text files I want to move are for the 14th of September, it takes FileDestinationPath and appends the date folder to the end of it. The text files have a date in the file name (test_09142006.txt) and I am picking this apart (from FileNameAndLocation in the For Each Loop) to get the folder date. (dts.Variables(“User::FileDestinationPath”).Value = dts.Variables(“User::FileDestinationPath”).Value & “\” Month & “_” & Day & “_” & Year & “\”) which gives me “C:\TestFiles\09_14_2006\”.

File System Task (within For Each Loop, second step) – This is where the action is supposed to occur. I want it to take the FileDestinationPath and move the FileNameAndLocation file (from the For Loop) into this folder for each run.

Now as for my problem. I want this package to run everyday but it has to set the FileDestinationPath variable dynamically according to that day’s date. Basically, how do I get this to work since I can’t hard code the destination path variable from the start? I have the DestinationVariable on the File System Task set to the FileDestinationPath variable, after the script task builds it. However, using FileNameAndLocation as the SourceVariable on my File System Task tells me that the “Variable “FileNameAndLocation” is used as a source or destination and is empty.”

Let me know if I need to clarify further…...I may be missing something very simple. Any help would be greatly appreciated!

Try 'harcoding' an initial value for FileDestinationPath variable. If my guess is correct, the designer is complain That value would be override by the scrip task result anyway.|||

Hi Rafael, thanks for the response. Unfortunately, that didn't work. What's strange is how I'm setting the FileNameAndLocation variable in the For Loop variable mapping but once it gets to the File System Task, it fails saying there is no valid path for the variable.

Do I even need to use a SourcePathVariable on the File System Task if I am simply moving files? I thought the Variable Mapping on the For Loop captures that for me, in the FileNameAndLocation variable?

I think I just confused myself.....

|||

dlackey wrote:

Hi Rafael, thanks for the response. Unfortunately, that didn't work. What's strange is how I'm setting the FileNameAndLocation variable in the For Loop variable mapping but once it gets to the File System Task, it fails saying there is no valid path for the variable.

Do I even need to use a SourcePathVariable on the File System Task if I am simply moving files? I thought the Variable Mapping on the For Loop captures that for me, in the FileNameAndLocation variable?

I think I just confused myself.....

Since you are moving multiple files (that is why you are using a ForEach loop container right?); you have to set IsDestinationPathVaribale and IsSourcePathVaribale to TRUE. Then you have to map DestinationVariable and SourceVariable properties to variables that contain both the path and the file name. I believe you are doing it right for the SourceVariable since you are using FileNameAndLocation which is populated by the ForEach loop container using ‘Fully qualified’ option. The problem, I am afraid, is in your DestinationVariable; if you use FileDestinationPath as you have it right now; it will give an error because is does not contain the file name. I would suggest to modify your script task to concatenate the file name as well.

Rafael Salas

|||

Thanks Rafael, I'll give it a try and let you know what I come up with.

Daniel Lackey

|||

I am working on the same thing at the moment. I have the File System Task setup with a DestinationConnection, then I am trying to use Expressions to change the connection string with a user variable. I have tried to use just the folder that I would like to change and the full path. I always seem to get the error that "The connection ... is not found" where the ... is the user variable. Any ideas would be appreciated.

Thanks,
TJ

|||

I just realized that I was using the expressions from the File System Task and not the expressions of the destination connection. I have it all working now. I am going to put in a few steps of how to do this since I had so much trouble finding information about it.

** I am assuming that everything is formatted for your export file and ready to export at this point.

1) Create a flat file destination.
2) In the properties of the Flat File Connection Manager (FFCM) (the items that show up in your connection managers tab) select the ... next to expressions
3) Select connection string on the left and click the ... on the right. In here you can build your file name.
4) If you are using a variable to change your file name, find your user variable in the tree on the left and drag it to the expression box. If you want something like a file name with the date with the file name then type what you want the file name to be (or use a variable) then add this for the year, month, and day (DT_WSTR,4) DATEPART("yy",GetDate()) + (DT_WSTR,2) DATEPART("mm",GetDate()) + (DT_WSTR,2) DATEPART("dd",GetDate()). Now click ok.
5) I would recommend that you test your package now and verify that your file name is now dynamic in the flat file connection folder.
6) Now to make the folder dynamic add a File System Task (FST) in the Control Flow.
7) Setup the FST with the FFCM that you created in the dataflow as the SourceConnection. Create a new FFCM for the DestinationConnection.
8) In the properties of the new FFCM select the ... next to the expressions.
9) In here you can change the folder location in the same way that you changed the file name.

I hope this saves a few people some time, because I had all sorts of trouble getting this to work. Please feel free to make any notes if I missed a step or if I made a mistake in one of the steps.

Good Luck,
TJ

|||

After days of staring at my package (haha, sounds funny) I figured out the problem. What was happening was my script that creates the destination folder that runs each time before the File System Task to move files, each time the For Each Loop iterates, I was adding the destination file to the DestinationFilePath variable each time. Hence, second iteration would result in 'C:\TestFiles\09_14_2006\09_14_2006' then third would be 'C:\TestFiles\09_14_2006\09_14_2006\09_14_2006' and so on and so on. Therefore, the File System Task would not find the destination file because it did not exist in the first place! ...resulting in my package failing. So as a result, I added a LoopCount to my script and and If statement so that the destination variable is only set on the first run through the loop.

So brief summary of what the package I built is doing (still in rough draft form by the way, but it finally at least works). I have 3 Variables in my project: DestinationFilePath set to C:\TestFiles, FileNameAndLocation set to C:\TestFiles, and LoopCount set to 1. The SSIS package contains a For Each Loop Container that contains a Script Task and a File System Task within it. The For Each Loop goes through my C:\TestFiles folder and enumerates through all files with .txt on the end of it. It sets the fully qualified name of the file to FileNameAndLocation variable in the Variable Mappings property for each iteration. Now, the Script Task builds the DestinationFilePath variable with this script:

Dim RightDate As String = Right(Dts.Variables("FileNameAndLocation").Value, 10)

Dim LeftDate As String = Left(RightDate, 4)

Dim Month As String = Left(LeftDate, 2)

Dim Day As String = Right(LeftDate, 2)

If Dts.Variables("LoopCount").Value = 1 Then

Dts.Variables("DestinationFilePath").Value = Dts.Variables("DestinationFilePath").Value & "\" & Month & "_" & Day & "_" & "2006\"

Dts.Variables("LoopCount").Value = 0

End If

The code is cheesy I know, but it works. I may refine it later. Especially for the year, since that can be different. But you get the point. So after that is set, I then on success move to the File System Task which sets the DestinationFilePath to the Destination Variable and the FileNameAndLocation as the Source Variable. It then moves the file and the For Each Loop moves on to the next one.

This solution works in that each day, the folder will contain that days .txt files. So the script will build a different DestiantionFilePath based upon the date in the file name.

Thanks for your input TJ, what you said will work too from what I can see. But since I was building the destination file name in a script task before the File System Task, I was able to avoid using any expressions or FFCMs.

Thanks for all of your help, I really do appreciate it!

Daniel

|||

Finally, with your post, I was able to get the dynamic file to update w/ current date.

Now how do I pass a variable from a column valuein a table to dynamically change the same filename?

My SQLCommand (select * from tableA) from datareadersource is connected to a flatfile destination. I need to pass

(product_order) from a column in this table-store the result in variable (prodID) and pass on as new filename in file system task.

How to do?

Sunday, February 26, 2012

File Share Subscription

I have been trying, unsuccessfully, to set up a File Share Subscription. (The path is a location not on the report server.) On the destination server, the network permissions are set to full and the NTFS permissions are set to modify.

I found a post that said a Shared Schedule had to be used for this to work, so I tried that with no luck either. This is the error message I'm receiving:

"Logon failure: unknown user name or bad password. "

However, I can manually map a drive from my machine to that network drive.

And we've also been able to set up the File Share subscription to deliver to a different location on the network w/o issue.

I found something on a blog but I'm not sure that it is accurate. I can't find anything in the help files that indicate this is true. Can anyone confirm or deny?

"...if it fails using any account other than the account that the account Reporting Services is running under

just run your app pools and the reporting services windows service under the same account.

then change the Reports (Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportManager) and ReportServer (Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer) web.config files so the “impersonation” is to false."|||

In the file share subscription,use your login name and your password as stored credentials, and test the subscription.

Local server accounts may not be in Active Directory and they may not have permissions to write files on another share.

Friday, February 24, 2012

file operations

I'm writing a proc to do tlog backups. I want to validate the path before
attempting to issue the backup command but I don't see any documented file
handling funtions in T-SQL. What's the best approach for this?
Thanks,
Bob Castleman
DBA PoseurImplement a DTS package that first uses the FSO.FileExists function via a
ActiveX Script task to verify the folder. If the task returns success, then
use a Execute SQL task to call your SP.
Function Main()
Main = DTSTaskExecResult_Failure
sCopyFrom = "c:\temp\xxx.tmp"
sCopyTo = "c:\temp\xxx.dat"
set FSO = CreateObject("Scripting.FileSystemObject")
if not FSO.FileExists( sCopyFrom ) then
exit function
end if
if FSO.FileExists( sCopyTo ) then
FSO.DeleteFile sCopyTo
end if
FSO.CopyFile sCopyFrom, sCopyTo
set FSO = nothing
Main = DTSTaskExecResult_Success
End Function
"Bob Castleman" <nomail@.here> wrote in message
news:e180EavYFHA.1028@.TK2MSFTNGP10.phx.gbl...
> I'm writing a proc to do tlog backups. I want to validate the path before
> attempting to issue the backup command but I don't see any documented file
> handling funtions in T-SQL. What's the best approach for this?
> Thanks,
> Bob Castleman
> DBA Poseur
>

File name includes file path in DTS Send Mail task - help

I have an issue with a DTS package. We create a zip file and then attach it to emails going out using DTS. The problem is that the attachment, when received, is named using the full path to the file, so it is quite long.

Has anyone seen this before? Is there a way out of this?

I am considering mapping a drive to the share holding the file to be named, but the fact is this will shorten the name but will still result in the path being included.

I am wondering if this is a bug, as I suspect this isn't the default behaviour.

Thank you in advance.

Davehow are you zipping the files? thru some command line statements? I dont think its related to DTS in any way.|||Are you talking about the file names inside the ZIP? or the name of the zip file?|||The files are zipped in a previous step. The values in the send mail step are dynamically set, but basically in the Add... for the attachment you get a path like:

\\computer\folder1\folder2\folder3\longzipfilename .zip

The attached file when received will be:

computerfolder1folder2folder3longzipfilename.zip

It is quite strange. The zip file name is only "longzipfilename.zip", and it is sitting in folder prior to the mail step, so I don't quite get it.

I hope that helps.

Thanks for the replys.|||It is strange, can you paste the send mail statements here? where name of the file is dynamically created.|||Originally posted by rohitkumar
It is strange, can you paste the send mail statements here? where name of the file is dynamically created.

I am stumpted. It looks like the file is displayed properly in Outlook but not in some other email clients, which makes me think this isn't a DTS issue after all. I am not at the site now, but essentially the value for the path of the file is getting passed along in the email. Since this is an intermittant problem (per Windows version or Outlook/Web Mail etc.) I don't believe it is something I can correct with any ease.