Click here to Skip to main content
15,914,820 members
Home / Discussions / Database
   

Database

 
AnswerRe: Aliasing Problem In SQL Query Pin
venkynataraj9-Mar-11 0:52
venkynataraj9-Mar-11 0:52 
AnswerRe: Aliasing Problem In SQL Query Pin
Prasanta_Prince15-Apr-11 1:00
Prasanta_Prince15-Apr-11 1:00 
GeneralRe: Aliasing Problem In SQL Query Pin
Anubhava Dimri15-Apr-11 1:06
Anubhava Dimri15-Apr-11 1:06 
QuestionTransactional Replicated Databases And Changing Schema Pin
wizardzz8-Mar-11 6:50
wizardzz8-Mar-11 6:50 
AnswerRe: Transactional Replicated Databases And Changing Schema Pin
Wendelius8-Mar-11 8:21
mentorWendelius8-Mar-11 8:21 
GeneralRe: Transactional Replicated Databases And Changing Schema Pin
wizardzz8-Mar-11 8:34
wizardzz8-Mar-11 8:34 
GeneralRe: Transactional Replicated Databases And Changing Schema Pin
Wendelius8-Mar-11 11:24
mentorWendelius8-Mar-11 11:24 
QuestionUnable to create database programmatically Pin
Helfdane7-Mar-11 10:44
Helfdane7-Mar-11 10:44 
Hi there,

I'm trying to create a database programmatically using .Net3.5 and C#. I have this nice SQL-script which works fine in the SSMS editor, but now to try it for real in C#. I learned that the GO-statements were only for the SSMS editor, so I removed those. (am I right on that one?). What am I missing here?

Context: MSSQL 2008R2, VS2008, .Net3.5, WindowsXP.

Below is my script. The error I get is the following:
Incorrect syntax near 'LOG'.\r\nDatabase 'dbName' does not exist. Make sure that the name is entered correctly.


The source I use to execute this script is here. (removed the try/catch/finally blocks etc)
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
string initDBQuery = string.Format(InstallationHelper.CreateDBScript(), settings.DatabaseLocation, settings.Database, settings.DatabaseUser, settings.DatabasePassword);
SqlCommand command = new SqlCommand(initDBQuery, conn);
command.ExecuteNonQuery();


This is the script (in C#-form):

            string script = 
            @"
            CREATE DATABASE [{1}] ON  PRIMARY ( NAME = N'{1}', FILENAME = N'{0}\{1}.mdf' , SIZE = 3072KB , FILEGROWTH = 1024KB );
            
            LOG ON ( NAME = N'{1}_log', FILENAME = N'{0}\{1}_log.ldf' , SIZE = 1024KB , FILEGROWTH = 10%);

            ALTER DATABASE [{1}] SET COMPATIBILITY_LEVEL = 100;

            ALTER DATABASE [{1}] SET ANSI_NULL_DEFAULT OFF ;

            ALTER DATABASE [{1}] SET ANSI_NULLS OFF ;

            ALTER DATABASE [{1}] SET ANSI_PADDING OFF ;

            ALTER DATABASE [{1}] SET ANSI_WARNINGS OFF ;

            ALTER DATABASE [{1}] SET ARITHABORT OFF ;

            ALTER DATABASE [{1}] SET AUTO_CLOSE OFF ;

            ALTER DATABASE [{1}] SET AUTO_CREATE_STATISTICS ON ;

            ALTER DATABASE [{1}] SET AUTO_SHRINK OFF ;

            ALTER DATABASE [{1}] SET AUTO_UPDATE_STATISTICS ON ;

            ALTER DATABASE [{1}] SET CURSOR_CLOSE_ON_COMMIT OFF ;

            ALTER DATABASE [{1}] SET CURSOR_DEFAULT  GLOBAL ;

            ALTER DATABASE [{1}] SET CONCAT_NULL_YIELDS_NULL OFF ;
 
            ALTER DATABASE [{1}] SET NUMERIC_ROUNDABORT OFF ;

            ALTER DATABASE [{1}] SET QUOTED_IDENTIFIER OFF ;

            ALTER DATABASE [{1}] SET RECURSIVE_TRIGGERS OFF ;

            ALTER DATABASE [{1}] SET  DISABLE_BROKER ;

            ALTER DATABASE [{1}] SET AUTO_UPDATE_STATISTICS_ASYNC OFF ;

            ALTER DATABASE [{1}] SET DATE_CORRELATION_OPTIMIZATION OFF ;

            ALTER DATABASE [{1}] SET PARAMETERIZATION SIMPLE ;

            ALTER DATABASE [{1}] SET  READ_WRITE ;

            ALTER DATABASE [{1}] SET RECOVERY SIMPLE ;

            ALTER DATABASE [{1}] SET  MULTI_USER ;

            ALTER DATABASE [{1}] SET PAGE_VERIFY CHECKSUM  ;

            USE [{1}];

            IF NOT EXISTS (SELECT name FROM sys.filegroups WHERE is_default=1 AND name = N'PRIMARY') ALTER DATABASE [{1}] MODIFY FILEGROUP [PRIMARY] DEFAULT;
";

A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)

AnswerRe: Unable to create database programmatically Pin
Wendelius7-Mar-11 11:56
mentorWendelius7-Mar-11 11:56 
GeneralRe: Unable to create database programmatically Pin
Helfdane8-Mar-11 1:24
Helfdane8-Mar-11 1:24 
GeneralRe: Unable to create database programmatically Pin
Wendelius8-Mar-11 8:21
mentorWendelius8-Mar-11 8:21 
AnswerRe: Unable to create database programmatically Pin
PIEBALDconsult7-Mar-11 16:34
mvePIEBALDconsult7-Mar-11 16:34 
AnswerRe: Unable to create database programmatically Pin
Roger Wright7-Mar-11 17:23
professionalRoger Wright7-Mar-11 17:23 
GeneralRe: Unable to create database programmatically Pin
Helfdane8-Mar-11 1:24
Helfdane8-Mar-11 1:24 
QuestionAudit Trail : Single table for all users or multiple table per user Pin
eight6-Mar-11 22:35
eight6-Mar-11 22:35 
AnswerRe: Audit Trail : Single table for all users or multiple table per user Pin
WoutL6-Mar-11 22:53
WoutL6-Mar-11 22:53 
AnswerRe: Audit Trail : Single table for all users or multiple table per user Pin
musefan6-Mar-11 22:57
musefan6-Mar-11 22:57 
GeneralRe: Audit Trail : Single table for all users or multiple table per user Pin
Dave Kerr6-Mar-11 23:03
mentorDave Kerr6-Mar-11 23:03 
GeneralRe: Audit Trail : Single table for all users or multiple table per user Pin
musefan6-Mar-11 23:36
musefan6-Mar-11 23:36 
AnswerRe: Audit Trail : Single table for all users or multiple table per user Pin
Eddy Vluggen7-Mar-11 0:15
professionalEddy Vluggen7-Mar-11 0:15 
AnswerRe: Audit Trail : Single table for all users or multiple table per user Pin
Wendelius7-Mar-11 1:52
mentorWendelius7-Mar-11 1:52 
QuestionUpgrading MSDE SP4 to SQL 2008 Express R2 Pin
Elsie6-Mar-11 19:46
Elsie6-Mar-11 19:46 
QuestionSQL Help - sum items based on max but also smaller than...? Pin
GlobX6-Mar-11 17:09
GlobX6-Mar-11 17:09 
AnswerRe: SQL Help - sum items based on max but also smaller than...? Pin
Wendelius7-Mar-11 7:40
mentorWendelius7-Mar-11 7:40 
GeneralRe: SQL Help - sum items based on max but also smaller than...? [modified] Pin
GlobX7-Mar-11 12:12
GlobX7-Mar-11 12:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.