UNC not recognized in stored proc variable

  • Is there a way to allow a UNC to be recognized within a stored procedure's variable on SQL 2000 SP4?

    I created a file on SERVERABC's E: drive called TRASH.bak

    This WORKS:

    declare @command nvarchar(4000)

    SELECT @command = 'master..xp_cmdshell ''del ' + 'e:\TRASH.BAK'''

    EXECUTE (@command)

    This DOESN'T:

    declare @command nvarchar(4000)

    SELECT @command = 'master..xp_cmdshell ''del ' + '\\SERVERABC\e:\TRASH.BAK'''

    EXECUTE (@command)

    BT
  • Hi there!

    It does work with UNC names. I just made a test and it works fine on SQL Server 2000 SP4.

    Here follows my test:

    declare @SQL VARCHAR(50)

    SET @SQL = 'xp_cmdshell ''dir \\d4253sd07\scripts$'''

    EXEC(@SQL)

    It returns this:

    Volume in drive \\d4253sd07\scripts$ is Dados

     Volume Serial Number is A4B7-87E2

    NULL

     Directory of \\d4253sd07\scripts$

    NULL

    31/08/2005  12:23       <DIR>          .

    31/08/2005  12:23       <DIR>          ..

    24/08/2005  15:34       <DIR>          DDL

    26/08/2005  12:24       <DIR>          Doncly

    Just a doubt... Are you using "e:" as share name? Also, as Lee Dise said, the share must be visible to the SQL Server Agent or SQL Server Service login.

  • Change it to use "e$" in place of "e:". someone correct me if I am wrong, but a UNC path it made up of:

    \\\

  • This might be a security problem. Check if the user executing the SP or the account under which the SQL server is running has enough right to access to network ressources or map drives.

     

    Cheers,

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply