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 6319291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:46:52+00:00 2026-05-24T15:46:52+00:00

There are a few similar questions on SO and elsewhere but mostly with php

  • 0

There are a few similar questions on SO and elsewhere but mostly with php and I do not understand that. I’m trying to restore a database with a 62 tables like this:

string query = @"SET SQL_MODE= 'NO_AUTO_VALUE_ON_ZERO'; CREATE DATABASE " + dbName + " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; USE " + dbName + ";" + Environment.NewLine;

using (StreamReader reader = File.OpenText("C:\b.sql"))
{
    string line = reader.ReadToEnd();
    query += line; //almost 1700 lines.
}
// upto this i get the query correctly which works fine in phpMyAdmin.

MySqlCommand c = new MySqlCommand(query, conn);
c.ExecuteReader();
//but when I execute, throws: "Fatal error encountered during command execution."

Why is this so? If it’s ‘cos of the length of the query, then how can I execute such large queries from the application?

  • 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-24T15:46:53+00:00Added an answer on May 24, 2026 at 3:46 pm

    try this for check error:

    List<string> query = new List<string>(){
            "SET SQL_MODE= 'NO_AUTO_VALUE_ON_ZERO';",
            string.Format("CREATE DATABASE `{0}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;", dbName),
            string.Format("USE `{0}`;", dbName)}; // error string.Format("USE `{0}`;{1}", dbName)
    /*    
    using (StreamReader reader = File.OpenText("C:\b.sql"))
    {
        while (reader.Peek() >= 0)
            query.Add(reader.ReadLine());
    }
    */
    
    using (StreamReader reader = File.OpenText("C:\b.sql"))
    {
        string lines = reader.ReadToEnd();
        string[] alines = lines.Split(';');
        foreach(string q in alines) 
                query.Add(q);
    }
    
    foreach (string command in query)
    {
        try
        {
            using (MySqlCommand c = new MySqlCommand(command, conn))
            {
                c.ExecuteReader();
                Console.WriteLine(string.Format("OK Command: {0}", command));
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(string.Format("Error: {0}. Command: {1}", ex.Message, command));
            break;
        }
    }
    

    Edit

    for better performance, you can use this class. I have not tried it, hope it works well:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using MySql.Data.MySqlClient;
    using System.IO;
    
    namespace MySQLHelperTest
    {
        public class MySQLTestingQuery
        {
            public MySqlConnection MyConnection { get; set; }
            public string FileSql { get; set; }
            public List<string> PreviousQuerys { get; set; }
            public List<string> CorrectQuerys { get; private set; }
            public string ErrorQuery { get; private set; }
    
            public MySQLTestingQuery()
            {
                this.CorrectQuerys = new List<string>();
                this.ErrorQuery = string.Empty;
            }
    
        public void Start()
        {
            FileInfo file = new FileInfo(this.FileSql);
            if (!file.Exists)
                throw new ApplicationException(string.Format("nonexistent file: '{0}'", this.FileSql));
    
            if (this.PreviousQuerys != null)
                foreach (string command in this.PreviousQuerys)
                    this.RunMySQLCommand(command);
    
            try
            {
                foreach (string command in this.ReadQuerys(this.FileSql))
                    Console.WriteLine(command);
            }
            catch (ApplicationException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new ApplicationException(string.Format("an unexpected error happened: {0}. ", ex.Message));
            }
    
        }
    
            private void RunMySQLCommand(string command)
            {
                try
                {
                    using (MySqlCommand c = new MySqlCommand(command, this.MyConnection))
                    {
                        c.ExecuteReader();
                        this.CorrectQuerys.Add(command);
                    }
                }
                catch (Exception ex)
                {
                    this.ErrorQuery = command;
                    throw new ApplicationException(string.Format("error: {0}. command: {1}", ex.Message, command));
                }
            }
    
            private IEnumerable<string> ReadQuerys(string file)
            {
                using (StreamReader sr = new StreamReader(file)) 
                {
                    string query = string.Empty;
                    while (sr.Peek() >= 0)
                    {
                        query += (char)sr.Read();
                        if (query.EndsWith(";"))
                        {
                            yield return query;
                            query = string.Empty;
                        }
                    }
                }
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am aware that there were similar questions in past few years, but after
I know there are a few questions about similar topics but they mostly amount
There have been a few questions that are similar but are either too broad
ok there are several similar questions but not quite anything that I want. I
There are a few similar questions on stackoverflow, but none of them seem to
There are a few similar questions to this but none quite the same. I
There were already a few similar questions on stackoverflow, but I haven't found the
I've looked over a few similar questions, but I'm still confused. I'm trying to
hope someone can help. I appreciate there are a few questions that are similar
There are a few similar questions out there on SO (links at end), but

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.