Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

i want to know the best way to save a sql database in locally throught my application and this back up file will be upload to online server.
Posted

With the help of BCP (Bulk Copy Program).i take a table back up in text file and then upload text file into sever.



Fist i take a back in local drive
fist take a windows form.in which add two button
1) backup
2) upload

click on backup button

private void btnBackup_Click(object sender, EventArgs e)
{
string path = "D:\\Backup\\";
string newpath = path.Replace("\\", "//");
filename = filename + ".txt";
dBTablename = "allot_table_copy";//This is a table name
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + "bcp DATABASENAEM.dbo." + dBTablename + " out " + path + filename + " -U sa -P lock123 -S RUMTEK7-PC\\BREEDSQLEXPRESS -c -E ");
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();

}

Now click on Upload button

To uploading this backup on online sqlserver

private void upload_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.ShowDialog();
DestinationPath = fbd.SelectedPath +"\\";
if (DestinationPath != "")
{
string newpath = DestinationPath.Replace("\\", "//");
filename = filename + ".txt";
dBTableName = "allot_table_copy";//Table name
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + "bcp DATABASE NAME.dbo." + dBTableName + " out " + DestinationPath + filename + " -U username-P password-S Hear is your ip -c -E ");
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
}
}
 
Share this answer
 
Just back it up via SQL Management Studio and then restore that backup on the online server. Remember to re-assign any user permissions required.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900