Database table creation error
-
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.
-
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.
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
-
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
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));
-
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));
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
-
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
Is is if you don't have system.Text referenced!
Never underestimate the power of human stupidity RAH
-
Is is if you don't have system.Text referenced!
Never underestimate the power of human stupidity RAH
True; my comment was rather flippant.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
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));
Off-hand I'd guess that it is the
GO
lines.