Please specify the version of SQL Server you are using. Assuming 2000,
there should be no difference in the Windows account used regardless of how
xp_cmdshell is run (proc vs. trigger executes proc). The process launched
from xp_cmdshell executes under the security context of the SQL Server
service account when run by a sysadmin role member. xp_cmdshell runs under
the configurable SQL Agent Proxy account for non-sysadmin users. The proxy
account can be configured from Enterprise Manager under Management-->SQL
Server Agent-->Properties-->Job System.
There are issues when running BCP from a trigger. A trigger always executes
in the context of a SQL Server transaction. Consequently, modified data
will be locked and cannot be accessed by the external BCP utility unless
NOLOCK is specified. Also, long-running transactions are bad for both
concurrency and performance.
I suggest you consider an alternative approach for your requirements. A
common practice is to insert the needed data into staging tables and
schedule a periodic SQL Agent job to generate the files.

Signature
Hope this helps.
Dan Guzman
SQL Server MVP
> To whom might be able to help me:
>
[quoted text clipped - 48 lines]
>
> Thanks a lot in advance.
Guillem Codina - 25 Jan 2006 08:50 GMT
Dear Dan,
Thanks for your help. You just guided me on the right direction; now I can
correctly execute the xp_cmdshell command in a stored procedure wich was
called from a trigger. To solve my problem I chosed to configure the SQL
Agent Proxy Account for non-sysadmin users.
I did not choose the alternative of inserting the data into staging tables
and scheduling a periodic SQL Agent job to transfer the file to the
communications daemon because I use some of the stored procedure's variables
to generate the file name (the Autonomous Port of Barcelona uses a quite
complex flat file naming standard) which needs to be different for each
vessel. This file also needs to be generated as soon as the vessel
operations are finished. Nevertheless, staging tables + sql agent job seems
at first a much more organized and less stressing way to perform these type
of tasks.
Again, THANKS A LOT FOR YOUR HELP.
"Dan Guzman" escribió:
> Please specify the version of SQL Server you are using. Assuming 2000,
> there should be no difference in the Windows account used regardless of how
[quoted text clipped - 67 lines]
> >
> > Thanks a lot in advance.
Dan Guzman - 25 Jan 2006 12:35 GMT
I'm glad the information was useful. You might also consider using a
trusted connection (-T parameter) for the BCP command rather than a
hard-coded userid and password. The proxy account will then need SELECT
permissions on the table to be exported.

Signature
Hope this helps.
Dan Guzman
SQL Server MVP
> Dear Dan,
>
[quoted text clipped - 102 lines]
>> >
>> > Thanks a lot in advance.