Home Forums Programming General Upload directory in Stored Procedure RE: Upload directory in Stored Procedure

  • rayh 98086 (5/6/2013)


    Hi,

    I am using a stored procedure and would like it to find a file on a different server location. When on the server, I have access to the drive using UNC or if I map a drive. However, when I try to do this within my Stored Procedure it does not work. Any suggestions to what the problem may be?

    The problem seems to be related to trying to reach the other server. (Could this be a network permission?)

    Here is my code:

    @GetFileName nvarchar(500),

    @filedir nvarchar(50),

    @cleanfilename nvarchar(500),

    @filepath nvarchar(500),

    @dircmd nvarchar(500),

    -- 1. Get File from Upload directory and pull out file name

    -- SET @filedir = 'Y:\' Mapped drive attempt

    SET @filedir = '\\servername\directory\'

    SET @cleanfilename = (SELECT SUBSTRING(@getfilename,4,100))

    SET @filepath = @filedir + @cleanfilename

    SET @dircmd = 'dir ' + @filepath

    Can you explain "does not work"? From what you posted I would expect that you get NULL as @cleanfilename because @getfilename is NULL. We need a little more detail here to know where to begin.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/