Click here to Skip to main content
15,887,820 members
Home / Discussions / C#
   

C#

 
GeneralRe: Control cannot fall through from one case to another? Pin
OriginalGriff13-May-09 5:57
mveOriginalGriff13-May-09 5:57 
AnswerRe: Control cannot fall through from one case to another? Pin
Lutosław13-May-09 8:38
Lutosław13-May-09 8:38 
QuestionDynamic Property in C# Pin
lnmca12-May-09 22:24
lnmca12-May-09 22:24 
AnswerRe: Dynamic Property in C# Pin
DaveyM6912-May-09 22:50
professionalDaveyM6912-May-09 22:50 
JokeRe: Dynamic Property in C# Pin
Giorgi Dalakishvili12-May-09 23:26
mentorGiorgi Dalakishvili12-May-09 23:26 
GeneralRe: Dynamic Property in C# Pin
DaveyM6913-May-09 2:29
professionalDaveyM6913-May-09 2:29 
QuestionEdit file as Pin
pedersen-roxen12-May-09 21:50
pedersen-roxen12-May-09 21:50 
Questionbackup database from a distant server with sql server 2000 Pin
adsana12-May-09 21:26
adsana12-May-09 21:26 
hello

i want to know how to backup a database from a distant server using c# and SqlServer2000.
NB:i just succeeded in doing this with a local server.
and here is the code:
[using System;

namespace test_backup
{ public partial class Form1 : Form
{ private static Server srvSql;
public Form1()
{ InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Create datatable where we enumerate the available servers

DataTable dtServers = SmoApplication.EnumAvailableSqlServers(true);

// If there are any servers at all

if (dtServers.Rows.Count > 0)
{

// Loop through each server in the DataTable

foreach (DataRow drServer in dtServers.Rows)
{

// Add the name to the combobox

cmbServer.Items.Add(drServer["Name"]);

}

}
}

private void button1_Click(object sender, EventArgs e)
{
// If a server was selected at all from the combobox

if (cmbServer.SelectedItem != null && cmbServer.SelectedItem.ToString() != "")
{

// Create a new connection to the selected server name

ServerConnection srvConn = new ServerConnection(cmbServer.SelectedItem.ToString());

// Log in using SQL authentication instead of Windows authentication

// srvConn.LoginSecure = false;

// Give the login username

//srvConn.Login ="."; //txtUsername.Text;

// Give the login password

// srvConn.Password =""; //txtPassword.Text;

// Create a new SQL Server object using the connection we created

srvSql = new Server(srvConn);

// Loop through the databases list

foreach (Database dbServer in srvSql.Databases)
{

// Add database to combobox

cmbDatabase.Items.Add(dbServer.Name);

}

}

else
{

// A server was not selected, show an error message

MessageBox.Show("Please select a server first", "Server Not Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}
}

private void button2_Click(object sender, EventArgs e)
{
// If there was a SQL connection created

if (srvSql != null)
{

// If the user has chosen a path where to save the backup file

// if (saveBackupDialog.ShowDialog() == DialogResult.OK)
// {

// Create a new backup operation

Backup bkpDatabase = new Backup();

// Set the backup type to a database backup

bkpDatabase.Action = BackupActionType.Database;

// Set the database that we want to perform a backup on

bkpDatabase.Database = cmbDatabase.SelectedItem.ToString();



// Set the backup device to a file

BackupDeviceItem bkpDevice = new BackupDeviceItem("d:\\sana22", DeviceType.File);

// Add the backup device to the backup

bkpDatabase.Devices.Add(bkpDevice);

// Perform the backup

bkpDatabase.SqlBackup(srvSql);

//}

}

else
{
// There was no connection established; probably the Connect button was not clicked

MessageBox.Show("A connection to a SQL server was not established.", "Not Connected to Server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}
}

private void button3_Click(object sender, EventArgs e)
{
// If there was a SQL connection created

if (srvSql != null)
{

// If the user has chosen the file from which he wants the database to be restored

// if (openBackupDialog.ShowDialog() == DialogResult.OK)
// {

// Create a new database restore operation

Restore rstDatabase = new Restore();

// Set the restore type to a database restore

rstDatabase.Action = RestoreActionType.Database;

// Set the database that we want to perform the restore on

rstDatabase.Database = cmbDatabase.SelectedItem.ToString();



// Set the backup device from which we want to restore, to a file

BackupDeviceItem bkpDevice = new BackupDeviceItem("d:\\sana22", DeviceType.File);

// Add the backup device to the restore type

rstDatabase.Devices.Add(bkpDevice);

// If the database already exists, replace it

rstDatabase.ReplaceDatabase = true;

// Perform the restore

rstDatabase.SqlRestore(srvSql);

// }

}

else
{

// There was no connection established; probably the Connect button was not clicked

MessageBox.Show("A connection to a SQL server was not established.", "Not Connected to Server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}
}
}]
QuestionDynamically ENUM Pin
lnmca12-May-09 19:13
lnmca12-May-09 19:13 
AnswerRe: Dynamically ENUM Pin
N a v a n e e t h12-May-09 19:17
N a v a n e e t h12-May-09 19:17 
GeneralRe: Dynamically ENUM Pin
PIEBALDconsult13-May-09 13:57
mvePIEBALDconsult13-May-09 13:57 
AnswerRe: Dynamically ENUM Pin
zlezj12-May-09 23:02
zlezj12-May-09 23:02 
AnswerRe: Dynamically ENUM Pin
Guffa13-May-09 0:48
Guffa13-May-09 0:48 
AnswerRe: Dynamically ENUM Pin
Paulo Zemek13-May-09 9:00
mvaPaulo Zemek13-May-09 9:00 
QuestionStandalone application.... Pin
Rajdeep.NET is BACK12-May-09 19:03
Rajdeep.NET is BACK12-May-09 19:03 
AnswerRe: Standalone application.... Pin
N a v a n e e t h12-May-09 19:22
N a v a n e e t h12-May-09 19:22 
GeneralRe: Standalone application.... Pin
Rajdeep.NET is BACK12-May-09 20:06
Rajdeep.NET is BACK12-May-09 20:06 
GeneralRe: Standalone application.... Pin
V.12-May-09 20:14
professionalV.12-May-09 20:14 
GeneralRe: Standalone application.... Pin
N a v a n e e t h12-May-09 20:27
N a v a n e e t h12-May-09 20:27 
GeneralRe: Standalone application.... Pin
OriginalGriff12-May-09 21:55
mveOriginalGriff12-May-09 21:55 
GeneralRe: Standalone application.... Pin
Guffa13-May-09 0:59
Guffa13-May-09 0:59 
AnswerRe: Standalone application.... Pin
Wes Aday13-May-09 10:32
professionalWes Aday13-May-09 10:32 
AnswerRe: Standalone application.... Pin
PIEBALDconsult13-May-09 14:36
mvePIEBALDconsult13-May-09 14:36 
QuestionRemove processes from memory on abnormal exit Pin
aastudent12-May-09 18:57
aastudent12-May-09 18:57 
AnswerRe: Remove processes from memory on abnormal exit Pin
N a v a n e e t h12-May-09 19:48
N a v a n e e t h12-May-09 19:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.