-
April 11th, 2010, 04:19 PM
#1
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.
-
April 12th, 2010, 06:32 PM
#2
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();
}
}
}
}
}
-
April 12th, 2010, 09:30 PM
#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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|