最近用sqlserver2000给客户做了DTS导数据的包,现在要把这些包迁移到其它的服务器上,方法总如下:
方法1:在要迁移的服务器上把包打开->另存为->选择“位置”中的“SQLserver”->选择要导入的服务器,用户,密码,点击保存就过去了。
方法2:
1)在要迁移的服务器上把包打开->另存为->选择“位置”中的“结构化存储文件”,在文件名中填入要保存的位置。
2)在要导入的服务器里,建下面的存储过程,然后运行即可:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[s_LoadPackageToServer]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[s_LoadPackageToServer]
GO
Create procedure s_LoadPackageToServer
@PackageName varchar(128) ,
@FileName varchar(500) ,
@Username varchar(100) ,
@Password varchar(100)
as
/*
exec s_LoadPackageToServer
@PackageName = 'mypackage' ,
@FileName = 'c:/dtspckgs/mypackage.dts' ,
@Username = 'sa' ,
@Password = 'pwd'
*/
declare @objPackage int
declare @rc int
exec @rc = sp_OACreate 'DTS.Package', @objPackage output
if @rc <> 0
begin
raiserror('failed to create package rc = %d', 16, -1, @rc)
return
end
exec @rc = sp_OAMethod @objPackage, 'LoadFromStorageFile' , null,
@UncFile = @FileName, @password = null
if @rc <> 0
begin
raiserror('failed to load package rc = %d, package = %s', 16, -1, @rc, @PackageName)
return
end
exec @rc = sp_OAMethod @objPackage, 'SaveToSQLServerAs' , null,
@NewName = @PackageName, @ServerName = @@ServerName, @ServerUserName = @Username, @ServerPassword = @Password
if @rc <> 0
begin
raiserror('failed to load package rc = %d, package = %s', 16, -1, @rc, @PackageName)
return
end
go
exec s_LoadPackageToServer
'mypackage' ,
'c:/DTS_AN2CP_DIC.dts' ,
'sa' ,
'sa'
发表评论 取消回复