CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2010
    Posts
    3

    C# MySql Server 5.1 help

    i'm building an application that creates a mySql db from script.sql file, i know that i have to run MySql server 5.1 Command Line Client and type this:

    MySql> source ..\filepath\MyScript.sql;

    now i need to run this command from my C# Application.

    thanx in adcvance.

  2. #2
    Join Date
    Oct 2009
    Location
    Harrisburg, PA
    Posts
    23

    Re: C# MySql Server 5.1 help

    this worked for me:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using System.IO;
    using MySql.Data.MySqlClient;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            string sqlStr = "";
            static void Main(string[] args)
            {
                Program prg = new Program();
                prg.CreateDatabase();
            }
    
            void CreateDatabase()
            {
                using (StreamReader reader = new StreamReader(@"C:\Users\Jamie\Desktop\Temp\localhost.sql"))
                {
                    sqlStr = reader.ReadToEnd();
                }
    
                MySqlConnectionStringBuilder cnxBldr = new MySqlConnectionStringBuilder();
                cnxBldr.Server = "192.168.27.5";
                cnxBldr.UserID = "admin";
                cnxBldr.Password = "password";            
    
                using (MySqlConnection cnx = new MySqlConnection(cnxBldr.ToString()))
                {
                    cnx.Open();
                    using (MySqlCommand sqlCmd = new MySqlCommand(sqlStr, cnx))
                    {
                        int result = sqlCmd.ExecuteNonQuery();                    
                    }
                }
            }
    
        }
    }

  3. #3
    Join Date
    Mar 2010
    Posts
    3

    Re: C# MySql Server 5.1 help

    thanx,
    it worked i knew that but it didn't come in my mind,

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured