You have ON [PRIMARY]
twice, but it should only be listed once.
Executing an SQL statement inside c# code gives error "Incorrect syntax near the keyword 'ON'"
-
30-06-2022 - |
سؤال
The code I have is pretty simple:
SqlCommand command = new SqlCommand("CREATE TABLE [dbo].[ClientData]([ClientDataID] [int] IDENTITY(1,1) NOT NULL,[SessionID] [char](24) NOT NULL,[Browser] [varchar](20) NOT NULL,[IP] [varchar](20) NOT NULL,[OperatingSystem] [varchar](30) NOT NULL,CONSTRAINT [PK_SessionData] PRIMARY KEY CLUSTERED([ClientDataID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ON [PRIMARY]");
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
command.Connection = connection;
command.ExecuteNonQuery();
}
Upon executing, I get this error:
Incorrect syntax near the keyword 'ON'
The query is generated by MS SQL 2008 and I just copied it as it was. Could someone please tell me why this doesn't work?
Thanks.
المحلول
نصائح أخرى
Use this script in SqlCommand.
CREATE TABLE [dbo].[ClientData]([ClientDataID] [int] IDENTITY(1,1) NOT NULL,[SessionID] char NOT NULL,[Browser] varchar NOT NULL,[IP] varchar NOT NULL,[OperatingSystem] varchar NOT NULL,CONSTRAINT [PK_SessionData] PRIMARY KEY CLUSTERED([ClientDataID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] )
NOT sure whether you are looking for this!
CREATE TABLE [dbo].[ClientData]
(
[ClientDataID] [int] IDENTITY(1,1)
NOT NULL,[SessionID] [char](24) NOT NULL,
[Browser] [varchar](20) NOT NULL,
[IP] [varchar](20) NOT NULL,
[OperatingSystem] [varchar](30) NOT NULL,
CONSTRAINT [PK_SessionData]
PRIMARY KEY CLUSTERED([ClientDataID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
لا تنتمي إلى StackOverflow