本文整理汇总了C#中Server.Refresh方法的典型用法代码示例。如果您正苦于以下问题:C# Server.Refresh方法的具体用法?C# Server.Refresh怎么用?C# Server.Refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server.Refresh方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RestoreDatabase
public void RestoreDatabase(String databaseName, String filePath, String serverName, String userName, String password, String dataFilePath, String logFilePath)
{
try
{
Restore sqlRestore = new Restore();
BackupDeviceItem deviceItem = new BackupDeviceItem(filePath, DeviceType.File);
sqlRestore.Devices.Add(deviceItem);
sqlRestore.Database = databaseName;
ServerConnection connection = new ServerConnection(serverName, userName, password);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[databaseName];
sqlRestore.Action = RestoreActionType.Database;
String dataFileLocation = dataFilePath + databaseName + ".mdf";
String logFileLocation = logFilePath + databaseName + "_Log.ldf";
db = sqlServer.Databases[databaseName];
RelocateFile rf = new RelocateFile(databaseName, dataFileLocation);
sqlRestore.RelocateFiles.Add(new RelocateFile(databaseName, dataFileLocation));
sqlRestore.RelocateFiles.Add(new RelocateFile(databaseName + "_log", logFileLocation));
sqlRestore.ReplaceDatabase = true;
sqlRestore.Complete += new ServerMessageEventHandler(sqlRestore_Complete);
sqlRestore.PercentCompleteNotification = 10;
sqlRestore.PercentComplete += new PercentCompleteEventHandler(sqlRestore_PercentComplete);
sqlRestore.SqlRestore(sqlServer);
db = sqlServer.Databases[databaseName];
db.SetOnline();
sqlServer.Refresh();
}
catch (SqlServerManagementException ex)
{
ex.Message.ToString();
}
}
示例2: SqlServerSchemaInspector
public SqlServerSchemaInspector(string connectionString)
{
Server server = new Server();
server.ConnectionContext.ConnectionString = connectionString;
server.Refresh();
string databaseName = ConnectionString_Regex.Match(connectionString).Groups["databaseName"].Value;
database = server.Databases[databaseName];
}
示例3: Button_Click_2
private void Button_Click_2(object sender, RoutedEventArgs e)
{
Restore rest = new Restore();
string PathtobackUp ="";
OpenFileDialog dlg = new OpenFileDialog();
dlg.InitialDirectory = "c:\\";
dlg.Filter = "Backup Files (*.bak)|*.bak|All Files (*.*)|*.*";
dlg.RestoreDirectory = true;
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
PathtobackUp = dlg.FileName.ToString();
}
else
{
return;
}
string fileName = PathtobackUp;
//this.Cursor = Cursors.WaitCursor;
//this.dataGridView1.DataSource = string.Empty;
try
{
rest.Devices.AddDevice(fileName, DeviceType.File);
Server srv = new Server("(localdb)\\v11.0");
bool verifySuccessful = rest.SqlVerify(srv);
string databaseName = "LoanManagement.Domain.finalContext";
if (verifySuccessful)
{
System.Windows.MessageBox.Show("Backup Verified!", "Info");
System.Windows.MessageBoxResult dr = System.Windows.MessageBox.Show("Do you want to restore?","Question",MessageBoxButton.YesNo);
if (dr == MessageBoxResult.Yes)
{
//fileName = dlg.FileName.Replace(Directory.GetCurrentDirectory(), "");
System.Windows.MessageBox.Show(fileName);
rest.Database = databaseName;
rest.Action = RestoreActionType.Database;
BackupDeviceItem bdi = default(BackupDeviceItem);
bdi = new BackupDeviceItem(fileName, DeviceType.File);
rest.Devices.Add(bdi);
//rest.Devices.Add(bdi);
rest.ReplaceDatabase = true;
srv = new Server("(localdb)\\v11.0");
rest.SqlRestore(srv);
srv.Refresh();
System.Windows.MessageBox.Show("Restore of " + databaseName +" Complete!");
}
}
else
{
System.Windows.MessageBox.Show("ERROR: Backup not verified!", "Error");
}
}
catch (Exception ex)
{
System.Windows.MessageBox.Show("The system has been successfully restored");
}
finally
{
//this.Cursor = Cursors.Default;
}
}
示例4: RollBackDatabase
public static void RollBackDatabase(string databaseName, string bakfilePath)
{
SqlConnection.ClearAllPools();
SqlConnection cnn = SetSingleUser(databaseName);
ServerConnection serverConn = new ServerConnection(cnn);
Server server = new Server(serverConn);
Database db = server.Databases[cnn.Database];
Restore restore = new Restore();
restore.Action = RestoreActionType.Database;
restore.Devices.AddDevice(bakfilePath, DeviceType.File);
restore.Database = databaseName;
restore.ReplaceDatabase = true;
restore.Complete += new ServerMessageEventHandler(Restore_Completed);
restore.PercentComplete += new PercentCompleteEventHandler(CompletionStatusInPercent);
restore.PercentCompleteNotification = 10;
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandText = string.Format("use master");
cmd.ExecuteNonQuery();
restore.SqlRestore(server);
db = server.Databases[databaseName];
db.SetOnline();
server.Refresh();
if (server.ConnectionContext.IsOpen)
server.ConnectionContext.Disconnect();
}
示例5: RefreshServer
private void RefreshServer(Server server)
{
server.Refresh();
}
示例6: PhucHoiDuLieu
private void PhucHoiDuLieu()
{
GetDatabaseInformation();
var cnn = new SqlConnection(_connectionString);
cnn.Open();
var conn = new ServerConnection(cnn);
var server = new Server(conn);
cnn.Close();
Restore restore = new Restore();
//string fileName = string.Format("{0}\\{1}.bak", testFolder, databaseName);
string fileName = txtTenTapTin.Text;
restore.Devices.Add(new BackupDeviceItem(fileName, DeviceType.File));
// Just give it a new name
//string destinationDatabaseName = string.Format("{0}_newly_restored", databaseName);
string destinationDatabaseName = txtCoSoDuLieu.Text;
// Go grab the current database’s logical names for the data
// and log files. For this example, we assume there are 1 for each.
//Database currentDatabase = server.Databases[databaseName];
//string currentLogicalData_ = currentDatabase.FileGroups[0].Files[0].Name;
//string currentLogicalLog_ = currentDatabase.LogFiles[0].Name;
// Now relocate the data and log files
//RelocateFile reloData = new RelocateFile(currentLogicalData, string.Format(@"{0}\{1}.mdf", testFolder, destinationDatabaseName));
//RelocateFile reloLog = new RelocateFile(currentLogicalLog, string.Format(@"{0}\{1}_Log.ldf", testFolder, destinationDatabaseName));
RelocateFile reloData = new RelocateFile(currentLogicalData, physicalFileName);
RelocateFile reloLog = new RelocateFile(currentLogicalLog, physicalFileLogName);
//MessageBox.Show(fileName);
//MessageBox.Show(destinationDatabaseName);
//MessageBox.Show(currentLogicalData);
//MessageBox.Show(currentLogicalLog);
//MessageBox.Show(currentLogicalData_);
//MessageBox.Show(currentLogicalLog_);
//MessageBox.Show(string.Format(@"{0}\{1}.mdf", testFolder, destinationDatabaseName));
//MessageBox.Show(string.Format(@"{0}\{1}_Log.ldf", testFolder, destinationDatabaseName));
//MessageBox.Show(physicalFileName);
//MessageBox.Show(physicalFileLogName);
restore.RelocateFiles.Add(reloData);
restore.RelocateFiles.Add(reloLog);
restore.Database = destinationDatabaseName;
restore.ReplaceDatabase = true;
restore.PercentCompleteNotification = 10;
restore.PercentComplete += restore_PercentComplete;
//restore.Complete += restore_Complete;
restore.ReplaceDatabase = true;
server.KillAllProcesses(txtCoSoDuLieu.Text);
restore.SqlRestore(server);
server.Refresh();
MessageBox.Show("Quá trình hoàn tất");
Bar.EditValue = 0;
Bar.Refresh();
//progressBar1.Value = 0;
//progressBar1.Refresh();
}
示例7: upload_DoWork
void upload_DoWork(object sender, DoWorkEventArgs e)
{
if (upload.CancellationPending)
{
e.Cancel = true;
return;
}
bool again = false;
bool attached = false;
First:
try
{
#region BackUp First
if (!serverMode)
{
BackUpDatabase bak = new BackUpDatabase();
bak.doBackUp();
}
#endregion
#region InitVariables and Save Info In File
progress = 1;
again = false;
attached = false;
progress = 2;
StreamWriter sw = new StreamWriter("UploadConfig.conf");
sw.WriteLine(destinationServer);
sw.WriteLine(destinationDatabase);
sw.WriteLine(username);
sw.WriteLine(MyCrypt.encryptWithDefaultValues(pass));
if (serverMode)
{
sw.WriteLine(sourceServer);
sw.WriteLine(sourceDatabase);
}
sw.Close();
sw.Dispose();
#endregion
#region ServerCreation and Delete All Objects On Destination Database
progress = 3;
ServerConnection destinationCon;
if (!String.IsNullOrEmpty(username) || !String.IsNullOrEmpty(pass))
{
destinationCon = new ServerConnection(destinationServer, username, pass);
}
else
{
destinationCon = new ServerConnection(destinationServer);
}
Server destServer = new Server(destinationCon);
String fp = Environment.CurrentDirectory + "\\query.sql";
FileInfo file = new FileInfo(fp);
string script = file.OpenText().ReadToEnd();
script = script.Replace("dbo", username);
try
{
destServer.ConnectionContext.ExecuteNonQuery(script);
}
catch (Exception excep)
{
MessageBox.Show("Error In Removing All Objects \n" + excep.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
//MessageBox.Show("خطای تکنیکی \n" + excep.InnerException.Message + "\n" + excep.StackTrace, "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
}
// Connect to server
Server server = new Server(sourceServer);
progress = 4;
#endregion
#region AttachDatabaseOnServer
progress = 5;
if (!serverMode)
{
System.Collections.Specialized.StringCollection files = new System.Collections.Specialized.StringCollection();
string datab = Environment.CurrentDirectory + "\\Negindb.mdf";
string logDb = Environment.CurrentDirectory + "\\Negindb_log.ldf";
files.Add(datab);
server.AttachDatabase(sourceDatabase, files);
attached = true;
server.Refresh();
}
progress = 6;
#endregion
#region DatabaseCreation
progress = 7;
//.........这里部分代码省略.........
示例8: RestoreUserMappings
private void RestoreUserMappings(Server server, IEnumerable<SqlServerUser> users, string databaseName)
{
server.Refresh();
var database = server.Databases[databaseName];
database.Refresh();
if (!users.Any())
{
Logger.WriteLine("No user mappings to restore");
return;
}
Logger.WriteLine("Restoring user mappings:");
foreach (var user in users)
{
TryCreate(database, user);
}
}
示例9: RestoreDatabase
/// <summary>
/// Restores a Database from backup file.
/// </summary>
/// <param name="connectionString">
/// The connection string provides the information for the database to be restored.
/// </param>
/// <param name="restoreFrom">
/// The backup file path.
/// </param>
public static void RestoreDatabase(string connectionString, string restoreFrom)
{
if (string.IsNullOrWhiteSpace(connectionString))
throw new ArgumentException("A valid sql connection is required. It cannot be null or white spaces.");
if (string.IsNullOrWhiteSpace(restoreFrom))
throw new ArgumentException("A valid back up file name is required. It cannot be null or white spaces.");
var sqlConnectionString = new SqlConnectionStringBuilder(connectionString);
string restoreDatabaseName = sqlConnectionString.InitialCatalog;
sqlConnectionString.InitialCatalog = "master";
using (var masterConnection = new SqlConnection(sqlConnectionString.ConnectionString))
{
var serverConnection = new ServerConnection(masterConnection);
var server = new Server(serverConnection);
Database restoreDatabase = server.Databases[restoreDatabaseName];
if (restoreDatabase != null)
{
// server.KillAllProcesses(restoreDatabaseName);
server.KillDatabase(restoreDatabaseName);
}
var restore = new Restore
{
NoRecovery = false,
ReplaceDatabase = true,
Action = RestoreActionType.Database,
Database = restoreDatabaseName,
PercentCompleteNotification = 10
};
var backupDeviceItem = new BackupDeviceItem(restoreFrom, DeviceType.File);
restore.Devices.Add(backupDeviceItem);
restore.SqlRestore(server);
restore.Devices.Remove(backupDeviceItem);
server.Refresh();
serverConnection.Disconnect();
}
}