Click here to Skip to main content
11,492,523 members (64,782 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 19-Jun-13 22:16pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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();
}
}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 454
1 Maciej Los 266
2 KarstenK 210
3 CPallini 208
4 Sascha Lefèvre 190
0 Sergey Alexandrovich Kryukov 10,062
1 OriginalGriff 8,620
2 Sascha Lefèvre 3,609
3 Maciej Los 3,372
4 Richard Deeming 2,500


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100