Click here to Skip to main content
15,888,454 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to disable the GotFocus on textbox? Pin
Mycroft Holmes27-Sep-11 21:11
professionalMycroft Holmes27-Sep-11 21:11 
AnswerRe: how to disable the GotFocus on textbox? Pin
xavjer28-Sep-11 3:48
xavjer28-Sep-11 3:48 
AnswerRe: how to disable the GotFocus on textbox? Pin
Eddy Vluggen28-Sep-11 7:42
professionalEddy Vluggen28-Sep-11 7:42 
QuestionLower resolution of .PDF Pin
Steve van Niman27-Sep-11 11:30
Steve van Niman27-Sep-11 11:30 
AnswerRe: Lower resolution of .PDF Pin
Dave Kreskowiak27-Sep-11 13:05
mveDave Kreskowiak27-Sep-11 13:05 
AnswerRe: Lower resolution of .PDF Pin
Alan Balkany28-Sep-11 5:42
Alan Balkany28-Sep-11 5:42 
AnswerRe: Lower resolution of .PDF Pin
BobJanova28-Sep-11 22:52
BobJanova28-Sep-11 22:52 
QuestionSQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
kutbinayi27-Sep-11 5:19
kutbinayi27-Sep-11 5:19 
Hi, in my project I tried to backup my database and then restore using SMO. While backing up and restoring it gives no errors and catches no exception. All of them seem to work great. However, after I perform backup to a file, I deleted the data and/or a table from my database to see whether restoring operation will perform correctly or not. However, when I deleted a table or just data in the table, if I perform restore operation, neither the table nor the data in the table comes back. As a result either backup or restore operation does not work correctly. My backup and restore methods are as in the following :

public bool BackUpDB(string DBpath)
        {
            try
            {
                // Create a new connection to the selected server name
                ServerConnection srvConn = new ServerConnection(Program.serverName);
                // Log in using SQL authentication instead of Windows authentication
                srvConn.LoginSecure = true;
                // Create a new SQL Server object using the connection we created
                srvr = new Server(srvConn);
                // If the user has chosen a path where to save the backup file
                // 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 = Program.databaseName;
                //set incremental to false because this is full backup
                bkpDatabase.Incremental = false;
                bkpDatabase.Initialize = true;
                //Specify that the log must be truncated after the backup is complete. 
                bkpDatabase.LogTruncation = BackupTruncateLogType.Truncate;
                // Set the backup device to a file
                BackupDeviceItem bkpDevice = new BackupDeviceItem(DBpath , DeviceType.File);
                // Add the backup device to the backup
                bkpDatabase.Devices.Add(bkpDevice);
                // Perform the backup
                bkpDatabase.SqlBackupAsync(srvr);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }



The following is my restore method :

public bool RestoreDB(string DBpath)
        {
            try
            {
                // Create a new connection to the selected server name
                ServerConnection srvConn = new ServerConnection(Program.serverName);
                // Log in using SQL authentication instead of Windows authentication
                srvConn.LoginSecure = true;
                // Create a new SQL Server object using the connection we created
                srvr = new Server(srvConn);
                // If the user has chosen the file from which he wants the database to be restored
                // Create a new database restore operation
                Restore rstDatabase = new Restore();
                // Set the restore type to a database restore
                rstDatabase.Action = RestoreActionType.Database;                

                // If specified database does not exist create it by using master database
                if (!srvr.Databases.Contains(Program.databaseName))
                {
                    try
                    {
                        DbConnection dbcon = new DbConnection("Data Source=" + Program.serverName + ";Initial Catalog=master;Integrated Security=True");
                        dbcon.ExecuteCommand("CREATE DATABASE "+Program.databaseName, null);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Veritabanı yaratılırken hata oluştu. Program yine de yedeğinizi geri yüklemeye çalışacak. Ancak bu değişiklik programınıza yansımayabilir. Bu durumda bizimle iletişime geçiniz.","Uyarı",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                    }
                }
                
                // Set the database that we want to perform the restore on
                rstDatabase.Database = Program.databaseName;
                
                rstDatabase.Devices.AddDevice(@DBpath, DeviceType.File);

                // If the database already exists, replace it
                rstDatabase.ReplaceDatabase = true;
                // Perform the restore
                rstDatabase.SqlRestoreAsync(srvr);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }


I searched on this issue a lot and all of the codes seems correct however I could not understand why it does not perform correctly. Anyone can help me on this issue ? Please it is a bit urgent, Thanks...
AnswerCrosspost Pin
Eddy Vluggen27-Sep-11 6:22
professionalEddy Vluggen27-Sep-11 6:22 
GeneralRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
kutbinayi27-Sep-11 6:30
kutbinayi27-Sep-11 6:30 
GeneralRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
Eddy Vluggen27-Sep-11 6:36
professionalEddy Vluggen27-Sep-11 6:36 
GeneralRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
kutbinayi27-Sep-11 6:41
kutbinayi27-Sep-11 6:41 
AnswerRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
Eddy Vluggen27-Sep-11 6:48
professionalEddy Vluggen27-Sep-11 6:48 
GeneralRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
kutbinayi27-Sep-11 7:53
kutbinayi27-Sep-11 7:53 
GeneralRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
Eddy Vluggen27-Sep-11 8:19
professionalEddy Vluggen27-Sep-11 8:19 
GeneralRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
kutbinayi27-Sep-11 8:29
kutbinayi27-Sep-11 8:29 
AnswerRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
Eddy Vluggen27-Sep-11 8:35
professionalEddy Vluggen27-Sep-11 8:35 
GeneralRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
kutbinayi27-Sep-11 8:48
kutbinayi27-Sep-11 8:48 
GeneralRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
Eddy Vluggen27-Sep-11 11:55
professionalEddy Vluggen27-Sep-11 11:55 
Question(Rich)TextBox problem! Pin
OlivierPD27-Sep-11 4:07
OlivierPD27-Sep-11 4:07 
AnswerRe: (Rich)TextBox problem! Pin
Luc Pattyn27-Sep-11 4:21
sitebuilderLuc Pattyn27-Sep-11 4:21 
GeneralRe: (Rich)TextBox problem! Pin
OlivierPD27-Sep-11 6:25
OlivierPD27-Sep-11 6:25 
GeneralRe: (Rich)TextBox problem! Pin
Pete O'Hanlon27-Sep-11 6:27
mvePete O'Hanlon27-Sep-11 6:27 
GeneralRe: (Rich)TextBox problem! Pin
OlivierPD27-Sep-11 6:41
OlivierPD27-Sep-11 6:41 
AnswerRe: (Rich)TextBox problem! Pin
Luc Pattyn27-Sep-11 7:21
sitebuilderLuc Pattyn27-Sep-11 7:21 

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.