Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7790193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:30:51+00:00 2026-06-01T21:30:51+00:00

In a small application I’m making for school, I’m attempting to determine if the

  • 0

In a small application I’m making for school, I’m attempting to determine if the necessary database exists.

If it does not, I want to create it (along with the tables in the database), and then use it as normal.

I’m using Visual C# Express Edition, along with SQL Server Express. I wrote the small test program below…

namespace DatabaseConnectionTest
{
    class Program
    {
        public static SqlConnection con;

        public static void EstablishConnection()
        {
            string userName = "username";
            string password = "password";
            string server = @".\SQLEXPRESS";
            string database = "Blibbity";
            string trustedConnection = "yes";
            string timeout = "30";

            try
            {
                con = new SqlConnection(
                        "user id=" + userName +
                        ";password=" + password +
                        ";server=" + server +
                        ";Trusted_Connection=" + trustedConnection +
                        ";database=" + database +
                        ";connection timeout=" + timeout);
                con.Open();
                Console.WriteLine("Connection successful!");

                var command = new SqlCommand("insert into sometable values ('somedata')", con);
                command.ExecuteNonQuery();
                Console.WriteLine("Insert successful!");

                command = new SqlCommand("select somecolumn from sometable", con);
                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    Console.WriteLine("Fectched data ====> " + reader["somecolumn"].ToString());
                }

                reader.Close();
                Console.WriteLine("Query successful!");

                command = new SqlCommand("delete from sometable where somecolumn = 'somedata'", con);
                command.ExecuteNonQuery();
                Console.WriteLine("Delete successful!");
            }
            catch
            {
                database = "master";

                con = new SqlConnection(
                    "user id=" + userName +
                    ";password=" + password +
                    ";server=" + server +
                    ";Trusted_Connection=" + trustedConnection +
                    ";database=" + database +
                    ";connection timeout=" + timeout);

                con.Open();

                var command = new SqlCommand(@"
                    USE [master]
                    GO

                    /****** Object:  Database [Blibbity]    Script Date: 04/12/2012 07:08:45 ******/
                    CREATE DATABASE [Blibbity] ON  PRIMARY 
                    ( NAME = N'Blibbity', FILENAME = N'c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\Blibbity.mdf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
                     LOG ON 
                    ( NAME = N'Blibbity_log', FILENAME = N'c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\Blibbity_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
                    GO

                    ALTER DATABASE [Blibbity] SET COMPATIBILITY_LEVEL = 100
                    GO

                    IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
                    begin
                    EXEC [Blibbity].[dbo].[sp_fulltext_database] @action = 'enable'
                    end
                    GO

                    ALTER DATABASE [Blibbity] SET ANSI_NULL_DEFAULT OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET ANSI_NULLS OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET ANSI_PADDING OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET ANSI_WARNINGS OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET ARITHABORT OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET AUTO_CLOSE OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET AUTO_CREATE_STATISTICS ON 
                    GO

                    ALTER DATABASE [Blibbity] SET AUTO_SHRINK OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET AUTO_UPDATE_STATISTICS ON 
                    GO

                    ALTER DATABASE [Blibbity] SET CURSOR_CLOSE_ON_COMMIT OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET CURSOR_DEFAULT  GLOBAL 
                    GO

                    ALTER DATABASE [Blibbity] SET CONCAT_NULL_YIELDS_NULL OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET NUMERIC_ROUNDABORT OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET QUOTED_IDENTIFIER OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET RECURSIVE_TRIGGERS OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET  DISABLE_BROKER 
                    GO

                    ALTER DATABASE [Blibbity] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET DATE_CORRELATION_OPTIMIZATION OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET TRUSTWORTHY OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET ALLOW_SNAPSHOT_ISOLATION OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET PARAMETERIZATION SIMPLE 
                    GO

                    ALTER DATABASE [Blibbity] SET READ_COMMITTED_SNAPSHOT OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET HONOR_BROKER_PRIORITY OFF 
                    GO

                    ALTER DATABASE [Blibbity] SET  READ_WRITE 
                    GO

                    ALTER DATABASE [Blibbity] SET RECOVERY SIMPLE 
                    GO

                    ALTER DATABASE [Blibbity] SET  MULTI_USER 
                    GO

                    ALTER DATABASE [Blibbity] SET PAGE_VERIFY CHECKSUM  
                    GO

                    ALTER DATABASE [Blibbity] SET DB_CHAINING OFF 
                    GO", con);

                command.ExecuteNonQuery();
                con.Close();

                database = "Blibbity";

                con = new SqlConnection(
                    "user id=" + userName +
                    ";password=" + password +
                    ";server=" + server +
                    ";Trusted_Connection=" + trustedConnection +
                    ";database=" + database +
                    ";connection timeout=" + timeout);

                con.Open();

                command = new SqlCommand(@"
                    USE [Blibbity]
                    GO

                    /****** Object:  Table [dbo].[sometable]    Script Date: 04/12/2012 07:09:07 ******/
                    SET ANSI_NULLS ON
                    GO

                    SET QUOTED_IDENTIFIER ON
                    GO

                    SET ANSI_PADDING ON
                    GO

                    CREATE TABLE [dbo].[sometable](
                        [somecolumn] [varchar](50) NULL
                    ) ON [PRIMARY]

                    GO

                    SET ANSI_PADDING OFF
                    GO", con);

                command.ExecuteNonQuery();
                con.Close();

                EstablishConnection();
            }
            finally
            {
                con.Close();
                Console.WriteLine("Connection now closed...");
                Console.ReadLine();
            }
        }

        static void Main(string[] args)
        {
            EstablishConnection();
        }
    }
}

Obviously Blibbity is just a junk database. It’s when I hit the first ExecuteNonQuery() line in the exception catch, it tells me that my syntax near "GO" is incorrect, yet I just copied the text for the database/table creation using SQL Server Management Studio’s “Script As CREATE TO” feature.

Does anybody know why I’m running into this issue?

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:30:52+00:00Added an answer on June 1, 2026 at 9:30 pm

    GO is not a sql server command, it is interpreted by Management studio. If you want to achieve the same behavior, than you have to split the sql command by the go instructions and execute each part sequentially.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a small application in GTK+ and java, and I want it
I'm writing a small application in CakePHP 2.1, and I want to use Nick
I am making a small application and would like a small popup to come
I made a small application and I am ready to distribute it. I want
I have a small application that does the following: allows the user to upload
I am creating a small application that will be deployed on Window. The database
I have a small AJAX application, written in PHP that I did not secure
I'm developing a small application that reads data from a database and displys it
I've made a small application for fun and I want to implement an update
I have a small application that has a message only WTL window which does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.