为了改善我公司软件的客户安装体验,我正在尝试找出一种从未安装 SSIS 的计算机远程部署 SSIS 包的方法。我希望客户无需在应用程序和 SQL/SSIS 服务器上运行安装程序。这可以通过工具或编程方式实现吗?我尝试以编程方式使用 Microsoft.SQLServer.ManagedDTS 库部署包,但收到“找不到集成服务类”的异常。由于我能够在未安装 SQL 的计算机上使用 System.Data.SqlClient 类运行数据库脚本,因此我希望 SSIS 也能有类似的东西。目前该软件需要支持SQL Server 2008-2012版本。
一种实现方法是使用TSQL在其他环境中实现该项目。我给您留下了一个通用示例脚本:
-- Define variables
DECLARE @FolderName NVARCHAR(128) = N'YourFolder';
DECLARE @ProjectName NVARCHAR(128) = N'YourProject';
DECLARE @EnvironmentName NVARCHAR(128) = N'Production';
DECLARE @ConnectionString NVARCHAR(4000) = N'your connection string here';
DECLARE @IspacPath NVARCHAR(4000) = N'C:\path\to\your\project.ispac';
DECLARE @ReferenceType INT = 50; -- Reference type for SSIS project
DECLARE @EnvironmentId INT;
DECLARE @ProjectId INT;
-- Create the folder if it doesn't exist
IF NOT EXISTS (SELECT 1 FROM [SSISDB].[catalog].[folders] WHERE [name] = @FolderName)
BEGIN
EXEC [SSISDB].[catalog].[create_folder]
@folder_name = @FolderName,
@folder_id = NULL;
END
-- Deploy the project to SSISDB catalog
DECLARE @operation_id BIGINT;
DECLARE @project_stream VARBINARY(MAX);
-- Read the .ispac file into a variable
SELECT @project_stream = CAST(bulkcolumn AS VARBINARY(MAX))
FROM OPENROWSET(BULK @IspacPath, SINGLE_BLOB) AS x;
-- Deploy the project
EXEC [SSISDB].[catalog].[deploy_project]
@folder_name = @FolderName,
@project_name = @ProjectName,
@project_stream = @project_stream,
@operation_id = @operation_id OUTPUT;
-- Get the Environment ID
SELECT @EnvironmentId = environment_id
FROM [SSISDB].[catalog].[environments]
WHERE [environment_name] = @EnvironmentName
AND [folder_name] = @FolderName;
-- Get the Project ID
SELECT @ProjectId = project_id
FROM [SSISDB].[catalog].[projects]
WHERE [project_name] = @ProjectName
AND [folder_id] = (SELECT folder_id FROM [SSISDB].[catalog].[folders] WHERE [name] = @FolderName);
-- Create the environment if it doesn't exist
IF @EnvironmentId IS NULL
BEGIN
EXEC [SSISDB].[catalog].[create_environment]
@folder_name = @FolderName,
@environment_name = @EnvironmentName;
-- Get the Environment ID after creation
SELECT @EnvironmentId = environment_id
FROM [SSISDB].[catalog].[environments]
WHERE [environment_name] = @EnvironmentName
AND [folder_name] = @FolderName;
END
-- Create the variable in the environment if it doesn't exist
IF NOT EXISTS (SELECT 1 FROM [SSISDB].[catalog].[environment_variables] WHERE [variable_name] = N'ConnectionString' AND [environment_id] = @EnvironmentId)
BEGIN
EXEC [SSISDB].[catalog].[create_environment_variable]
@folder_name = @FolderName,
@environment_name = @EnvironmentName,
@variable_name = N'ConnectionString',
@sensitive = 0,
@description = N'Connection string for production',
@value = @ConnectionString;
END
-- Assign the environment to the project if it's not assigned
IF NOT EXISTS (SELECT 1 FROM [SSISDB].[catalog].[environment_references] WHERE [environment_name] = @EnvironmentName AND [project_name] = @ProjectName AND [folder_name] = @FolderName)
BEGIN
EXEC [SSISDB].[catalog].[create_environment_reference]
@folder_name = @FolderName,
@project_name = @ProjectName,
@environment_name = @EnvironmentName,
@reference_type = @ReferenceType,
@reference_id = @EnvironmentId;
END
-- Assign the environment variable to the project parameter if it's not assigned
IF NOT EXISTS (SELECT 1 FROM [SSISDB].[catalog].[object_parameters] WHERE [parameter_name] = N'$Project::ConnectionString' AND [object_name] = @ProjectName AND [folder_name] = @FolderName)
BEGIN
EXEC [SSISDB].[catalog].[set_object_parameter_value]
@folder_name = @FolderName,
@project_name = @ProjectName,
@parameter_name = N'$Project::ConnectionString',
@parameter_value = N'@[$Environment::ConnectionString]';
END