在执行xp_cmdshell时,不可显示申明事务:
you can try:declare @theStr varchar(500)
declare @b int
begin
truncate table sales --此句改了 set @theStr='bcp "pubs.dbo.sales" in c:\temp1.txt -c -S"hdlm" -U"sa" -P"admin"'
--print @theStr
exec @b=master..xp_cmdshell @theStr
end
you can try:declare @theStr varchar(500)
declare @b int
begin
truncate table sales --此句改了 set @theStr='bcp "pubs.dbo.sales" in c:\temp1.txt -c -S"hdlm" -U"sa" -P"admin"'
--print @theStr
exec @b=master..xp_cmdshell @theStr
end
事物内只能有:
insert
delete
update
语句!
begin tran t1
declare @theStr varchar(500)
delete from ImportTable --注意此句
set @theStr='bcp "db1..ImportTable" in e:\ImportTable\05-12-2003--3-14PM.txt -c -SLL -Usa -Pfortune'
print @theStr
exec @b=master..xp_cmdshell @theStr
commit tran t1