|
Hi sr159,
Please do not re-post the question.
You have already posted it here[^], and got resolution.
Please read guidelines[^] for better understanding of how to get answer and post question in this forum.
Hope you understand.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
hi sr159,
Why you have down voted me and removed your message?
Do not remove your message once you posted it, if it has
answers under it.
The question posted by sr159 is as follow
[Edit]
some changes made like form load and creating function and it is executing and also that is taking values from dump file but again not saving to database. please reply me
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
restore_data("temple1");
}
catch (Exception ex)
{
Application.Exit();
}
}
public void restore_data(string database)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe");
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <{4}", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = file.ReadToEnd();
p.WaitForExit();
file.Close();
}
}
}
[/Edit]
Hope you understand.
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
how to restore mysql dump file to database using C#
i am using following code but not working, if u know anyone please reply me
public void restore_data(string temple1)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo();
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <(4)", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = file.ReadToEnd();
p.WaitForExit();
file.Close();
}
modified on Friday, July 16, 2010 3:18 AM
|
|
|
|
|
hi,
There isn't any option available to import mysql dump file directly to
sql server. Because the data exported by mysql as dump is not compatible
with sql server to restore at one go.
You need to use phpmyadmin or some other tool to export mysql database
(export as excel or some other format that is compatible in sql server),
instead of taking dump directly from command prompt.
And then try to restore it.
However, if you have to restore backup file of sql server into another
database (sql server to sql server) then it is absolutely possible in
C# using SQL SMO.
Find following link for the same.
http://www.geekpedia.com/tutorial180_Backup-and-restore-SQL-databases.html[^]
http://www.mssqltips.com/tip.asp?tip=1849[^]
And please use pre tag to format your code and mark your "Message Type" as "Question" not as "General".
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
we are using mysqlserver 2005 and sql yog for database management not sql server 2005
but the code which we are using is not working
|
|
|
|
|
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <(4)", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
I think the first issue is in the bracket you are using for 4th argument.
Instead of () you need to use {}.
Along with it you need to change one more line as follows.
ProcessStartInfo proc = new ProcessStartInfo(@"[FullPath]\mysql.exe");
because it will find mysql.exe file only if you put it in windows directory along
with supporting files.
And that's it. I have tried the same at my local machine with the code you have
provided and changes I have suggested, and it's running fine.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
i written and changed the like following code as you said but it is running the form but not updating to database. i think exe is not generating. previously exe cmd promt was coming for taking dump like that it is not coming
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void restore_data(string temple1)
{
StreamReader file = new treamReader("E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump");
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <{4}", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = file.ReadToEnd();
p.WaitForExit();
file.Close();
}
}
}
|
|
|
|
|
some changes made like form load and creating function and it is executing and also that is taking values from dump file but again not saving to database. please reply me
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
restore_data("temple1");
}
catch (Exception ex)
{
Application.Exit();
}
}
public void restore_data(string database)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe");
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <{4}", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = file.ReadToEnd();
p.WaitForExit();
file.Close();
}
}
}
|
|
|
|
|
some changes made like form load and creating function and it is executing and also that is taking values from dump file but again not saving to database. please reply me
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
restore_data("temple1");
}
catch (Exception ex)
{
Application.Exit();
}
}
public void restore_data(string database)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe");
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <{4}", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = file.ReadToEnd();
p.WaitForExit();
file.Close();
}
}
}
|
|
|
|
|
Ok, I have found the problem and also resolution.
Consider following points in resolution.
1. Don't provide password when you are building arguments. You need to provide it later on
when you prompted for it.
2. you need to give filename as cmd.exe instead of mysql, because it will come under the
arguments.
For example, build your arguments as follows
string cmd = string.Format(@"C:\wamp\bin\mysql\mysql5.1.36\bin\mysql.exe -u {0} -p -h {1} {2} < {3}", "root", "localhost", "test123", @"C:\wamp\bin\mysql\mysql5.1.36\bin\wp.sql");
ProcessStartInfo proc = new ProcessStartInfo("cmd", @"/C " + cmd);
proc.UseShellExecute = false;
Process p = new Process();
p.StartInfo = proc;
p.Start();
p.WaitForExit();
See it I have not provided password. It should ask me for the password when I execute the process.
And that's it. It is now importing mysqldump file successfully.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
i changed as per instruction but again it is running but not saving to database and also not asking password and also we are not using wamp, we are using mysql 5.0. Please help.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
restore_data("temple1");
}
catch (Exception ex)
{
Application.Exit();
}
}
public void restore_data(string database)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
string cmd = string.Format(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\cmd.exe -u{0} -p -h{1} (2) < {3} ", "root", "localhost", '"' + database + '"', "E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo("cmd", @"/C " + cmd);
//proc.RedirectStandardInput = true;
//proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
//Process p = Process.Start(proc);
string res;
//res = file.ReadToEnd();
//p.WaitForExit();
//file.Close();
Process p = new Process();
p.StartInfo = proc;
p.Start();
res = file.ReadToEnd();
p.WaitForExit();
}
}
}
|
|
|
|
|
i changed as per instruction but again it is running but not saving to database and also not asking password and also we are not using wamp, we are using mysql 5.0. Please help.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
restore_data("temple1");
}
catch (Exception ex)
{
Application.Exit();
}
}
public void restore_data(string database)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
string cmd = string.Format(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\cmd.exe -u{0} -p -h{1} (2) < {3} ", "root", "localhost", '"' + database + '"', "E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo("cmd", @"/C " + cmd);
//proc.RedirectStandardInput = true;
//proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
//Process p = Process.Start(proc);
string res;
//res = file.ReadToEnd();
//p.WaitForExit();
//file.Close();
Process p = new Process();
p.StartInfo = proc;
p.Start();
res = file.ReadToEnd();
p.WaitForExit();
}
}
}
|
|
|
|
|
hi sr159,
You are not reading my answer. Again running wrong command.
Just read my answer carefully. I have supplied mysql instead of cmd command.
Instead of below line...
string cmd = string.Format(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\cmd.exe -u{0} -p -h{1} (2) < {3} ", "root", "localhost", '"' + database + '"', "E:\\BackupMysql1\\temple.sql");
Just use the line...
string cmd = string.Format(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe -u{0} -p -h{1} (2) < {3} ", "root", "localhost", '"' + database + '"', "E:\\BackupMysql1\\temple.sql");
And now execute the command. And try to edit your question not re-post or posting totally new question as reply by changing the message type.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
i changed cmd.exe to mysql.exe then also it is executing but not saving dump file to database using C#.
|
|
|
|
|
after running the processor which is taking the path is D:\the application folder name and not asking password.
|
|
|
|
|
problem solved now it is working thank you for all who replied to me
|
|
|
|
|
Thanks in advance.
how to convert a windows long path name to short pathname in VB.Net.
|
|
|
|
|
Find following code useful for the same.
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)]
string path,
[MarshalAs(UnmanagedType.LPTStr)]
StringBuilder shortPath,
int shortPathLength
);
public static void Main()
{
StringBuilder shortPath = new StringBuilder(255);
GetShortPathName(@"D:\My Temp\ResourseProvider\sql.txt", shortPath, shortPath.Capacity);
Console.WriteLine(shortPath.ToString());
}
The code is in C#, however you can do the same with syntactical changes in vb.net.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
I dunno who downvoted you, but I ran your code and it returned a correct answer. I got
E:\MYTEMP~1\RESOUR~1\sql.txt
However, it will fail if the path does not exist. Try the API on an existing path, and it will work.
I are Troll
|
|
|
|
|
thanks for the reply. Can you please give the code in vb.net syntax.
|
|
|
|
|
Imports System
Imports System.Runtime.InteropServices
Imports System.Text
Namespace Test
Class Program
<DllImport("kernel32.dll", CharSet := CharSet.Auto)> _
Public Shared Function GetShortPathName( _
<MarshalAs(UnmanagedType.LPTStr)> path As String, _
<MarshalAs(UnmanagedType.LPTStr)> shortPath As StringBuilder, _
shortPathLength As Integer _
) As Integer
End Function
Public Shared Sub Main()
Dim shortPath As New StringBuilder(255)
GetShortPathName( _
"E:\My Temp\ResourseProvider\sql.txt", _
shortPath, _
shortPath.Capacity)
Console.WriteLine(shortPath.ToString())
Console.ReadKey()
End Sub
End Class
End Namespace
There you are
I are Troll
|
|
|
|
|
hi experts,
my windows forms application, is unable to be executed in a PC where dotnet is not installed.
the reason i expect would be, because, iam using a dll in my application.
though i make a release version, there is no use.
please let me know if any details are required from my side.
any suggestions to get through my problem would be appreiciable.
thanks in advance,
chandu.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Are you sure that all dll libraries that you reference are installed on the target machine? Also you need to be sure that the machine supports the version of .NET that you have compiled against.
It's time for a new signature.
|
|
|
|
|
Running a Windows .NET application requires the presence of Windows and .NET
If you use an installer, make .NET one of the prerequisites there.
|
|
|
|
|
|