--看看这个,邹建是作者
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_movefile]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_movefile]
GO/*--在文本文件中追加数据在文本文件中追加数据
如果文件不存在,将创建文件--邹建 2004.08(引用请保留此信息)--*//*--调用示例exec p_movefile 'c:\aa.txt','测试写入'
--*/
create proc p_movefile
@filename varchar(1000),--要操作的文本文件名
@text varchar(8000) --要写入的内容
as
declare @err int,@src varchar(255),@desc varchar(255)
declare @obj intexec @err=sp_oacreate 'Scripting.FileSystemObject',@obj out
if @err<>0 goto lberrexec @err=sp_oamethod @obj,'OpenTextFile',@obj out,@filename,8,1
if @err<>0 goto lberrexec @err=sp_oamethod @obj,'WriteLine',null,@text
if @err<>0 goto lberrexec @err=sp_oadestroy @obj
returnlberr:
exec sp_oageterrorinfo 0,@src out,@desc out
select cast(@err as varbinary(4)) as 错误号
,@src as 错误源,@desc as 错误描述
go

解决方案 »

  1.   

    创建上面的SP时有没有出现下面的提示?
    Cannot add rows to sysdepends for the current stored procedure because it depends on the missing object 'sp_oacreate'. The stored procedure will still be created.
      

  2.   

    没有任何提示,但也没有生成aa.txt文件,即使先创建好aa.txt文件,也没有将"测试写入"信息写入到aa.txt文件中。
      

  3.   

    你的SQL SERVER 补丁打过没有啊? 这个过程我怎么试怎么成功的.
      

  4.   

    不好意思,这个存储过程只会在服SQL server所在的电脑上的C:下生成一个aa.txt文件,我一直都是使用查询分析器连到服务器上,在本机上的SQL server上试,可以了。万分感谢。