April 6, 2010 at 3:17 am
When I executes Database creation sqlscript programmatically through .NET. It gives "Incorrect syntax near 'GO'.". My sql script is
USE [master]
GO
/****** Object: Database [test] Script Date: 04/06/2010 14:30:46 ******/
CREATE DATABASE [test] ON PRIMARY
( NAME = N'test', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\test.mdf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'test_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\test_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [test] SET COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [test].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [test] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [test] SET ANSI_NULLS OFF
GO
ALTER DATABASE [test] SET ANSI_PADDING OFF
GO
ALTER DATABASE [test] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [test] SET ARITHABORT OFF
GO
ALTER DATABASE [test] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [test] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [test] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [test] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [test] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [test] SET CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [test] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [test] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [test] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [test] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [test] SET DISABLE_BROKER
GO
ALTER DATABASE [test] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [test] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [test] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [test] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [test] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [test] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [test] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [test] SET READ_WRITE
GO
ALTER DATABASE [test] SET RECOVERY SIMPLE
GO
ALTER DATABASE [test] SET MULTI_USER
GO
ALTER DATABASE [test] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [test] SET DB_CHAINING OFF
GO
Please help me
April 6, 2010 at 3:42 am
GO as a command means nothing to Sqlserver. It is used by management studio to break the commands into separate batches. You need to send you commands in one block (without GO) or separate statements.
April 6, 2010 at 3:47 am
So how can I create scripts without Go using sql management studio
April 6, 2010 at 3:54 am
You dont.
You need to send the commands batches ( ie each GO block) separately to SQLServer.
April 6, 2010 at 4:01 am
One doubt mate, are u trying to run this piece of code in SSMS 2005 or SSMS 2008?
April 6, 2010 at 4:03 am
Its SSMS 2008.
April 6, 2010 at 4:06 am
For SQL Server 2005, the compatiblity level can maximum be 90 and there is no command like HONOR_BROKER_PRIORITY
I tried this code in both SQL 2005 and 2008. i got error for the 2 properties i said above for 2005 and in 2008 it got compiled well...
April 6, 2010 at 4:07 am
So why state, "sqlscript programmatically through .NET" ?
April 6, 2010 at 4:16 am
Hmmm..
Tel me if u did this:
1. You Right-click on the database, "Create To" to a new SQL Server Window
2. SAve this script as .sql file
3. And now u are trying to run this .sql file using some .Net code.
Is that right man? or are u trying to run the script from SSMS itself??
April 6, 2010 at 4:19 am
Yes you are right. I am doing these steps.
April 6, 2010 at 4:25 am
Is your .Net Code executing the .sql thro sqlcmd/isql or is it reading the whole database creation query into a string and then executing the string using ExecuteQuery ?
April 6, 2010 at 7:09 am
Amit,
Please write down what you are doing. Type "I execute this in SSMS 2008 and get an error" or "I run this through .NET" and don't have people guessing about the issue.
We are more than happy to help, but it doesn't appear you have been clear about how you are receiving the error.
April 6, 2010 at 7:16 am
amit.jaura 81056 (4/6/2010)
So how can I create scripts without Go using sql management studio
Tools -> Options
SQL Server Object Explorer -> Scripting
"Delimit individual statements" ... set this to 'False'
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply