SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


trigger to call a program to write a text file onto a folder in the server


trigger to call a program to write a text file onto a folder in the server

Author
Message
eseeweb
eseeweb
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 60
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.
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)SSC Guru (210K reputation)

Group: General Forum Members
Points: 210719 Visits: 41973
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Steve Jones
Steve Jones
SSC Guru
SSC Guru (143K reputation)SSC Guru (143K reputation)SSC Guru (143K reputation)SSC Guru (143K reputation)SSC Guru (143K reputation)SSC Guru (143K reputation)SSC Guru (143K reputation)SSC Guru (143K reputation)

Group: Administrators
Points: 143732 Visits: 19424
Jeff Moden (4/30/2014)


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.


+1

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
crmitchell
crmitchell
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1248 Visits: 1793
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.






Does your command shell proxy account have adequate privileges set on the destination folder and does it have network privileges (the built in local service account will have local admin rights but no network privileges - other accounts including the network service account will need permissions set)?

Have you considered creating an SSIS package to poll the table write to the table and tidy up for this rather than a trigger? It would be easier to handle error conditions.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search