首页 运维 网络学院 查看内容

利用SQL移动硬盘文件

2012-1-31 14:11 815 0

摘要: 以下的代码将演示如何利用SQL数据库进行硬盘文件的移动:if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_...
关键词: movefile varchar err exec 错误 文件 file lberr obj desc

以下的代码将演示如何利用SQL数据库进行硬盘文件的移动: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  /*--移动服务器上的文件  不借助 xp_cmdshell ,因为这个在大多数时候都被禁用了  --邹建 2004.08(引用请保留此信息)--*/  /*--调用示例  exec p_movefile 'd:\aa.txt','c:\'  --*/  create proc p_movefile  @s_file varchar(1000), --源文件  @d_file varchar(1000) --目标文件  as  declare @err int,@src varchar(255),@desc varchar(255)  declare @obj int  exec @err=sp_oacreate 'Scripting.FileSystemObject',@obj out  if @err<>0 goto lberr  exec @err=sp_oamethod @obj,'MoveFile',null,@s_file,@d_file  if @err<>0 goto lberr  exec @err=sp_oadestroy @obj  return  lberr:  exec sp_oageterrorinfo 0,@src out,@desc out  select cast(@err as varbinary(4)) as 错误号  ,@src as 错误源,@desc as 错误描述  go
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部