I am working on a CLR stored procedure using VS2010. I need to create a standalone deployment script to install this procedure on client servers. Now I use Visual Studio, which generate such a script when I press F5 and try to debug the SP on the database server. This script is placed in a file bin\Debug\MyStoredProcedure.sql. It looks like this:
USE [$(DatabaseName)]
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE
GO
CREATE TABLE
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
GO
BEGIN TRANSACTION
GO
PRINT N'Dropping [dbo].[spMyStoredProcedure]...';
GO
DROP PROCEDURE [dbo].[spMyStoredProcedure];
GO
IF @@ERROR <> 0
AND @@TRANCOUNT > 0
BEGIN
ROLLBACK;
END
IF @@TRANCOUNT = 0
BEGIN
INSERT INTO
VALUES (1);
BEGIN TRANSACTION;
END
GO
PRINT N'Dropping [MyStoredProcedure]...';
GO
DROP ASSEMBLY [MyStoredProcedure];
GO
IF @@ERROR <> 0
AND @@TRANCOUNT > 0
BEGIN
ROLLBACK;
END
IF @@TRANCOUNT = 0
BEGIN
INSERT INTO
VALUES (1);
BEGIN TRANSACTION;
END
GO
PRINT N'Creating [MyStoredProcedure]...';
GO
CREATE ASSEMBLY [MyStoredProcedure]
AUTHORIZATION [dbo]
-- here should be long hex string with assembly binary
FROM 0x4D5A90000300000004000000FFFCD21546869732070726F6772616D...000000000000000000
WITH PERMISSION_SET = SAFE;
GO
IF @@ERROR <> 0
AND @@TRANCOUNT > 0
BEGIN
ROLLBACK;
END
IF @@TRANCOUNT = 0
BEGIN
INSERT INTO
VALUES (1);
BEGIN TRANSACTION;
END
GO
PRINT N'Creating [dbo].[spMyStoredProcedure]...';
GO
CREATE PROCEDURE [dbo].[spMyStoredProcedure]
@reference UNIQUEIDENTIFIER, @results INT OUTPUT, @errormessage NVARCHAR (4000) OUTPUT
AS EXTERNAL NAME [MyStoredProcedure].[MyCompany.MyProduct.MyStoredProcedureClass].[MyStoredProcedureMethod]
GO
IF @@ERROR <> 0
AND @@TRANCOUNT > 0
BEGIN
ROLLBACK;
END
IF @@TRANCOUNT = 0
BEGIN
INSERT INTO
VALUES (1);
BEGIN TRANSACTION;
END
GO
IF EXISTS (SELECT * FROM
GO
IF @@TRANCOUNT>0 BEGIN
PRINT N'The transacted portion of the database update succeeded.'
COMMIT TRANSACTION
END
ELSE PRINT N'The transacted portion of the database update failed.'
GO
DROP TABLE
GO
, script Visual Studio? , , MSBuild, script - ? , , script - , , , ?
.