Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Database table creation error

Database table creation error

Scheduled Pinned Locked Moved Database
databasecomhelpquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    solomon201
    wrote on last edited by
    #1

    I am trying to create a database and it's tables programmatically. I am following the Instructions from the link below but i keep getting this error ExecuteNonQuery failure. Please can someone look at the code? especially the table generation part because the Database creates but there are no tables in it.

    Create a SQL Database Programmatically[^]

    L 1 Reply Last reply
    0
    • S solomon201

      I am trying to create a database and it's tables programmatically. I am following the Instructions from the link below but i keep getting this error ExecuteNonQuery failure. Please can someone look at the code? especially the table generation part because the Database creates but there are no tables in it.

      Create a SQL Database Programmatically[^]

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      You should indicate what database server and programming language you are using, show (the relevant part of) the actual code, and the exact error message(s) you are getting; without any detailed information, all we can give you is a wild guess: maybe the table name you have chosen clashes with an SQL keyword. :)

      Luc Pattyn [My Articles] Nil Volentibus Arduum

      S 1 Reply Last reply
      0
      • L Luc Pattyn

        You should indicate what database server and programming language you are using, show (the relevant part of) the actual code, and the exact error message(s) you are getting; without any detailed information, all we can give you is a wild guess: maybe the table name you have chosen clashes with an SQL keyword. :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        S Offline
        S Offline
        solomon201
        wrote on last edited by
        #3

        I am using SQL Server 2008 R2 with C# running VS2010 The Code that gives the Error is this: StringBuilder sb = new StringBuilder(); try { sb.AppendLine(string.Format("Starting to create {0} with login to {1}", this.tbDBName.Text, this.tbBTSAppUser.Text)); sb.AppendLine("Connecting to DB Server"); this.tbProgress.Text = sb.ToString(); this.tbProgress.ScrollToCaret(); //Connect to the local, default instance of SQL Server. string srvname = this.cbServers.SelectedItem as string; Server srv; if (srvname == null) { srv = new Server(); sb.AppendLine("Connected to local SQL server"); } else { srv = new Server(srvname); sb.AppendLine(string.Format("Connected to {0}", srvname)); } this.tbProgress.Text = sb.ToString(); this.tbProgress.ScrollToCaret(); //Define a Database object variable by supplying the server and the database name arguments in the constructor. Database db = srv.Databases[this.tbDBName.Text.Trim()]; if (db != null) { if (MessageBox.Show(string.Format("The '{0}' already exists do you want to drop it?", this.tbDBName.Text), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { db.Drop(); } else { if (MessageBox.Show(string.Format("Create the Tables and Stored Procedures for BT Error Manager on '{0}'?", this.tbDBName.Text), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { sb.AppendLine("Creating the Tables and Stored Procedures."); this.tbProgress.Text = sb.ToString(); db.ExecuteNonQuery(dbstring); string ConnectionString = "Integrated Security=SSPI;" + sb.AppendLine(string.Format("Created the Tables and Stored Procedures for BT Error Manager on '{0}'", this.tbDBName.Text));

        L P 2 Replies Last reply
        0
        • S solomon201

          I am using SQL Server 2008 R2 with C# running VS2010 The Code that gives the Error is this: StringBuilder sb = new StringBuilder(); try { sb.AppendLine(string.Format("Starting to create {0} with login to {1}", this.tbDBName.Text, this.tbBTSAppUser.Text)); sb.AppendLine("Connecting to DB Server"); this.tbProgress.Text = sb.ToString(); this.tbProgress.ScrollToCaret(); //Connect to the local, default instance of SQL Server. string srvname = this.cbServers.SelectedItem as string; Server srv; if (srvname == null) { srv = new Server(); sb.AppendLine("Connected to local SQL server"); } else { srv = new Server(srvname); sb.AppendLine(string.Format("Connected to {0}", srvname)); } this.tbProgress.Text = sb.ToString(); this.tbProgress.ScrollToCaret(); //Define a Database object variable by supplying the server and the database name arguments in the constructor. Database db = srv.Databases[this.tbDBName.Text.Trim()]; if (db != null) { if (MessageBox.Show(string.Format("The '{0}' already exists do you want to drop it?", this.tbDBName.Text), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { db.Drop(); } else { if (MessageBox.Show(string.Format("Create the Tables and Stored Procedures for BT Error Manager on '{0}'?", this.tbDBName.Text), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { sb.AppendLine("Creating the Tables and Stored Procedures."); this.tbProgress.Text = sb.ToString(); db.ExecuteNonQuery(dbstring); string ConnectionString = "Integrated Security=SSPI;" + sb.AppendLine(string.Format("Created the Tables and Stored Procedures for BT Error Manager on '{0}'", this.tbDBName.Text));

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Please edit this message and put your code between <pre> tags so it is readable. You also need to indicate the line that gives the error and the exact error message that you see.

          solomon201 wrote:

          The Code that gives the Error is this:
           
          StringBuilder sb = new StringBuilder();

          That is not possible.

          Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

          M 1 Reply Last reply
          0
          • L Lost User

            Please edit this message and put your code between <pre> tags so it is readable. You also need to indicate the line that gives the error and the exact error message that you see.

            solomon201 wrote:

            The Code that gives the Error is this:
             
            StringBuilder sb = new StringBuilder();

            That is not possible.

            Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            Is is if you don't have system.Text referenced!

            Never underestimate the power of human stupidity RAH

            L 1 Reply Last reply
            0
            • M Mycroft Holmes

              Is is if you don't have system.Text referenced!

              Never underestimate the power of human stupidity RAH

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              True; my comment was rather flippant.

              Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

              1 Reply Last reply
              0
              • S solomon201

                I am using SQL Server 2008 R2 with C# running VS2010 The Code that gives the Error is this: StringBuilder sb = new StringBuilder(); try { sb.AppendLine(string.Format("Starting to create {0} with login to {1}", this.tbDBName.Text, this.tbBTSAppUser.Text)); sb.AppendLine("Connecting to DB Server"); this.tbProgress.Text = sb.ToString(); this.tbProgress.ScrollToCaret(); //Connect to the local, default instance of SQL Server. string srvname = this.cbServers.SelectedItem as string; Server srv; if (srvname == null) { srv = new Server(); sb.AppendLine("Connected to local SQL server"); } else { srv = new Server(srvname); sb.AppendLine(string.Format("Connected to {0}", srvname)); } this.tbProgress.Text = sb.ToString(); this.tbProgress.ScrollToCaret(); //Define a Database object variable by supplying the server and the database name arguments in the constructor. Database db = srv.Databases[this.tbDBName.Text.Trim()]; if (db != null) { if (MessageBox.Show(string.Format("The '{0}' already exists do you want to drop it?", this.tbDBName.Text), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { db.Drop(); } else { if (MessageBox.Show(string.Format("Create the Tables and Stored Procedures for BT Error Manager on '{0}'?", this.tbDBName.Text), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { sb.AppendLine("Creating the Tables and Stored Procedures."); this.tbProgress.Text = sb.ToString(); db.ExecuteNonQuery(dbstring); string ConnectionString = "Integrated Security=SSPI;" + sb.AppendLine(string.Format("Created the Tables and Stored Procedures for BT Error Manager on '{0}'", this.tbDBName.Text));

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                Off-hand I'd guess that it is the GO lines.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups