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

  • Home
  • SEARCH
  • 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 6758745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:50:18+00:00 2026-05-26T13:50:18+00:00

I am getting a Fatal Error on using a ExecuteNonQuery(). I’m new to working

  • 0

I am getting a Fatal Error on using a ExecuteNonQuery().
I’m new to working with sql and as such im not sure why this SET command is causing a problem.

I’m using MySql 5.5.17, and I’m using C# .Net Framework 3.5 in the VS2010 IDE.

Exception Message = Fatal error encountered during command execution.
The Error Line = SET @oldguid = 250006;

the content from the sql file im using is as follows minus the “comments” that i removed:

DELETE FROM `disables` WHERE `sourceType`=0 AND `entry`=61904;
INSERT INTO `disables` (`sourceType`, `entry`, `flags`, `comment`) VALUES(0, 61904, 8, 'Magma Totem TEST - can crash client by spawning too many totems');
SET @oldguid = 250006;
SET @newguid = 202602;
UPDATE `creature` SET `guid`=@newguid WHERE `guid`=@oldguid;
UPDATE `creature_addon` SET `guid`=@newguid, `path_id`=@newguid*100 WHERE `guid`=@oldguid;
UPDATE `waypoint_data` SET `id`=@newguid*100 WHERE `id`=@oldguid*100;
UPDATE `areatrigger_teleport` SET `target_orientation`=2.255664 WHERE `id`=4386;
UPDATE `gameobject` SET `spawnMask`=3 WHERE `guid`=22674;

the guid column is a unsigned int(10)

the C# code I am using to process this .sql file is as follows:

filename = lstBox_SqlFiles.SelectedItem.ToString();
mysql = new MySqlConnection(connection + Database);
string line;

OpenDatabase();
using (StreamReader reader = new StreamReader(filename))
{
  StringBuilder parsedLine = new StringBuilder();
  int count = 0;
  while ((line = reader.ReadLine()) != null)
  {
    if (line.Length > 0 && !line.StartsWith("--"))
    {
      if (line.EndsWith(";"))
      {
        if (parsedLine.Length > 0)
          line = parsedLine.ToString() + line;
        try
        {
          count++;
          lbl_LineQuery.Text = line;
          lbl_QueryCount.Text = String.Format("Count: {0}", count);

          MySqlCommand cmd = new MySqlCommand(line, mysql);
          cmd.ExecuteNonQuery();
        }
        catch (MySqlException ex)
        {
          string msg = String.Format("Source FileName: SqlUpdater.cs\nSql FileName: {0}\nError Line: {1}\nException Message: {2}\n", filename, line, ex.Message);
          MessageBox.Show("cmd.ExecuteNonQuery() Error!\n" + msg, "MySql Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
          return;
        }
        sbClear(parsedLine);
      }
      else
      {
        parsedLine.Append(line);
        continue;
      }
    }
    else
    continue;
  }
}

Can anyone see a problem with my code? Is there some special manipulation of the “SET @var” string that I need to do?

Any Help is appreciated
Thanks in advance

roadmaster

  • Edit * as a side note i should point out that if i use a sql management program like SQLYog it processes the same sql file with no problem so im assuming that the problem is somewhere in the manipulation of the string in my C# code.
  • 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-05-26T13:50:18+00:00Added an answer on May 26, 2026 at 1:50 pm

    Actually, I don’t think that you can pass this line SET @oldguid = 250006; into a mysqlcommand object (actually I don’t know). What you should do is have your program put these values in a local variable, and then replace the parameter in your update queries.

    Find a way to mix your code and this one:

            // This line should be outside the While loop
            Dictionary<string, string> variables = new Dictionary<string, string>();
    
    
            if (line.Trim().ToUpper().StartsWith("SET"))
            {
                List<string> commandLine;
                commandLine = line.Trim(' ',';').Split().Distinct().ToList();
                commandLine.Remove(string.Empty);
    
                // After next line, the 'variables' dictionary contains the name 
                // of the variable you want to set, and its value
                variables[commandLine[1]] = commandLine[3];
    
                // ...
                // Do something here (try catch, chatever, but NO MySqlCommand)
                // ...
            }
            else
            {
                // If the line contains any of the variables you previously set,
                // i will be the index of this variable, -1 otherwise
                int i = line.ContainsAnyOfAt(variables.Keys);
                while(i>=0)
                {
                    // Here we replace the parameter by its value, for example:
                    // UPDATE `creature` SET `guid`=@newguid WHERE `guid`=@oldguid;
                    // becomes (after all loops):
                    // UPDATE `creature` SET `guid`=202602 WHERE `guid`=250006;
                    line = line.Replace(variables.Keys.ElementAt(i), variables.Values.ElementAt(i));
                    i = line.ContainsAnyOfAt(variables.Keys,i+1);
                }
    
                // ...
                // This is where you should put the code of MySqlCommand
                // ...
            }
    

    And here is the extension method ContainsAnyOfAt :

            public static int ContainsAnyOfAt<T>(this global::System.String source, IEnumerable<T> values, int startIndex = 0)
            {
                if (source == null) throw new ArgumentNullException("source");
                for (int i = startIndex ; i < values.Count(); i++)
                {
                    if (source.Contains(values.ElementAt(i).ToString()))
                    {
                        return i;
                    }
                }
                return -1;
            }
    

    Please give it a try and give feedback.
    Greetings

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

Sidebar

Related Questions

I'm getting the old familiar Fatal error: Using $this when not in object context
I am getting a Fatal error: Using $this when not in object context in
I'm getting a fatal PHP error when trying to execute my script: Using $this
I am getting the error OperationalError: FATAL: sorry, too many clients already when using
I'm testing my project using pylint and currently getting fatal error when importing the
guys i'm getting this error Fatal error: Uncaught OAuthException: Error validating access token. thrown
I keep on getting this error when running one of my scripts; PHP Fatal
Using Zend FW based Youtube api. Often getting errors on page load Fatal error:
I am using CakePHP and getting the following error Warning: Cache not configured properly.
I'm getting Fatal error: Class 'Form_Login' not found in /route/to/project/application/controllers/AuthController.php on line XX when

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.