0

I am trying to execute a sql query which will create a new table in sql database. When I am doing this:

string queryString = @"
CREATE TABLE [dbo].[peep_searchresults_live](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [SKU] [varchar](150) NULL,
    [ManufacturerBrand] [varchar](150) NULL,
);

The query gets executed just fine and the table gets created in the database.

But when I am trying this:

string queryString = @"
            SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[peep_searchresults_live](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [SKU] [varchar](150) NULL,
    [ManufacturerBrand] [varchar](150) NULL,            
 CONSTRAINT [PK_peep_searchresults_live] PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO";

I am receiving error like this one:

enter image description here

2
  • what function are you using in the c# code? ExecuteNonQuery? Commented Mar 1, 2012 at 20:27
  • @Mr correct, I am using ExecuteNonQuery for that Commented Mar 1, 2012 at 20:38

3 Answers 3

3

SQL server doesn't understand what GO is - only the query analyzer knows (eg. SSMS).

If you need to execute multiple commands, simply execute them in the proper order, one at a time.

Sign up to request clarification or add additional context in comments.

Comments

0

GO statements are not valid in ADO.net

Do you need all of those other qualifying statements?

You can break each into a separate command, and execute each command in turn with a single connection.

1 Comment

I am trying to set primary key on ID field, is there other way how I can do via the code?
0

You cannot use go, you need to split the command in to multiple sets.

http://social.msdn.microsoft.com/Forums/ar/csharpgeneral/thread/2907541f-f1cf-40ea-8291-771734de55f2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.