我想知道如何创建一个文本文件并将其保存在我的本地机器上,下面是我正在使用的存储过程。它在服务器上创建文本文件,但我希望它在我的本地机器上创建。
任何帮助深表感谢..
alter Procedure [dbo].[USP_SaveFile]
(@text as NVarchar(Max), @Filename Varchar(200)) AS
Begin
declare
@Object int,
@rc int,
@FileID Int
EXEC @rc = sp_OACreate 'Scripting.FileSystemObject', @Object OUT
EXEC @rc = sp_OAMethod @Object , 'OpenTextFile' , @FileID OUT , @Filename , 2 , 1
Set @text = Replace(Replace(Replace(@text,'&','&'),'<' ,'<'),'>','>')
EXEC @rc = sp_OAMethod @FileID , 'WriteLine' , Null , @text
Exec @rc = [databasename].dbo.sp_OADestroy @FileID
Declare @Append bit
Select @Append = 0
If @rc <> 0
Begin
Exec @rc = [databasename].dbo.sp_OAMethod @Object, 'SaveFile',null,@text ,@Filename,@Append
End
Exec @rc = [databasename].dbo.sp_OADestroy @Object
End
-- Use [databasename]
-- EXEC sp_configure 'show advanced options', 1
-- GO
-- EXEC sp_configure 'Ole Automation Procedures', 1;
-- GO
-- RECONFIGURE;
-- GO
-- EXEC USP_SaveFile 'Microsoft SQL Server 2008', 'D:\sqlfiles\test.txt'