Home Forums SQL Server 2008 T-SQL (SS2K8) trigger to call a program to write a text file onto a folder in the server RE: trigger to call a program to write a text file onto a folder in the server

  • eseeweb (4/30/2014)


    hi

    I just have an update that we don't need to delete the record from the table as long as every time a record inserted can be write to a text file for the other side to consume. So, i did a quick test like this and have access denied issue.

    exec master.xp_cmdshell 'echo hello > c:\file.txt' which try to write to the c drive on the sql server.

    but if i quality it as

    exec master.xp_cmdshell 'echo hello > \\myPC\c$\file.txt'

    The issue is when i log on to sql server, i can add/write/mod files from c drive. Any reason? How to i use "execute as" statement?

    thx, Ted.

    SQL Server needs to have the privs to write to whatever UNC you're using. I STRONGLY recommend that you NEVER have SQL Server writing to UNCs that are desktop servers. I can see it writing to company shares on a dedicated share box but not to desktop PCs.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)