I have created a SQL Trigger as below.
create trigger testtrigger on testdb
declare @sql varchar(8000)
SELECT @sql = 'bcp "select * from testdb" queryout c:\output.txt -c -t -T -S localhost'
exec xp_cmdshell @sql
But when a row inserted in the testdb, the text file is created, but there is no content. Can someone please help me to resolve this.
Because row is inserted after trigger probably. If you insert a new record row #1 probably will show up in the file
I have tried inserting many rows. But there was nothing in the file.
Look in the SQL Server error log. Likely something is failing. Perhaps you don't have authority to write to C:<filename>.
The bcp command is working when I run it directly in the command prompt.
Do I have an option to see what's happening when the trigger is executing to know the exact error and on which step it is failing.