Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Execute a query with embedded GOs

Author  Topic 

pithhelmet
Posting Yak Master

183 Posts

Posted - 2008-09-10 : 09:19:10
Hi everyone,

I am utilizing the red-gate comparison tools,
and I can view the script that is generated from the comparison.

/*
Script created by SQL Compare version 6.2.1 from Red Gate Software Ltd at 9/10/2008 9:16:12 AM
Run this script on 10.20.16.192.AppLog to make it the same as 10.10.16.14.AppLog
Please back up your database before running this script
*/
SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
GO
CREATE TABLE #tmpErrors (Error int)
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
PRINT N'Creating [dbo].[tbltest]'
GO
CREATE TABLE [dbo].[tbltest]
(
[test] [nchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)

GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[testing]'
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE testing
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT getdate()
END

GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT>0 BEGIN
PRINT 'The database update succeeded'
COMMIT TRANSACTION
END
ELSE PRINT 'The database update failed'
GO
DROP TABLE #tmpErrors
GO


The question is....

Using C# winforms application, what command do i use to execute this block of code against the server????


using a cmd.executenonquery fails stating the syntax is incorrect at the GO 's

thanks
tony

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-09-10 : 09:25:22
you can do it with SMO if you use this method:

http://technet.microsoft.com/en-us/library/microsoft.sqlserver.management.common.serverconnection.executenonquery(SQL.90).aspx

SMO uses a parser that will parse out the GOs just like the query editor in SSMS does.


elsasoft.org
Go to Top of Page
   

- Advertisement -