public void sFillListAvailableDatabasesSqlAuth(string pServerName, string pLogIn = "", string pPassword = "")
        {
            try {
                Microsoft.SqlServer.Management.Common.ServerConnection vConn = new Microsoft.SqlServer.Management.Common.ServerConnection(pServerName, pLogIn, pPassword);
                Microsoft.SqlServer.Management.Smo.Server vServer            = new Microsoft.SqlServer.Management.Smo.Server(vConn);
                vConn.Connect();

                foreach (Database vDB2 in vServer.Databases)
                {
                    TXT_Database.Items.Add(vDB2.Name);
                }
            } catch (Exception vEx) {
                return;
            }
        }
Exemple #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            string _instance             = "localhost";
            string _repertoireSauvegarde = @"C:\Documents and Settings\Guillaume\SQLSave";

            string _horodatage = DateTime.Now.ToString("yyyyMMdd_hhmmss");

            smoCommon.ServerConnection sc = new smoCommon.ServerConnection(_instance);
            sc.Connect();
            smo.Server myServer = new smo.Server(sc);
            foreach (smo.Database myDb in myServer.Databases)
            {
                if (myDb.Name == "GEST_INFIRMERIE")
                {
                    smo.Backup myBackup = new smo.Backup();
                    myBackup.Database = myDb.Name;

                    // Définit le type de sauvegarde à effectuer  (base ou log)
                    myBackup.Action = smo.BackupActionType.Database;

                    // Sauvegarde FULL = false, Sauvegarde DIFF = true
                    myBackup.Incremental = false;

                    // Activation de la compression de la sauvegarde
                    myBackup.CompressionOption = smo.BackupCompressionOptions.Default;

                    // Ajout du device. Ici il s'agit d'un fichier mais on pourrait envisager une sauvegarde sur bande
                    myBackup.Devices.AddDevice(_repertoireSauvegarde + myDb.Name + "_" + _horodatage + ".bak", smo.DeviceType.File);
                    try
                    {
                        myBackup.SqlBackup(myServer);
                        Console.WriteLine(myDb.Name + " sauvegardée à " + DateTime.Now.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            sc.Disconnect();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            string _instance = "localhost";
            string _repertoireSauvegarde = @"C:\Documents and Settings\Guillaume\SQLSave";

            string _horodatage = DateTime.Now.ToString("yyyyMMdd_hhmmss");
            smoCommon.ServerConnection sc = new smoCommon.ServerConnection(_instance);
            sc.Connect();
            smo.Server myServer = new smo.Server(sc);
            foreach (smo.Database myDb in myServer.Databases)
            {
                if (myDb.Name == "GEST_INFIRMERIE")
                {
                    smo.Backup myBackup = new smo.Backup();
                    myBackup.Database = myDb.Name;

                    // Définit le type de sauvegarde à effectuer  (base ou log)
                    myBackup.Action = smo.BackupActionType.Database;

                    // Sauvegarde FULL = false, Sauvegarde DIFF = true
                    myBackup.Incremental = false;

                    // Activation de la compression de la sauvegarde
                    myBackup.CompressionOption = smo.BackupCompressionOptions.Default;

                    // Ajout du device. Ici il s'agit d'un fichier mais on pourrait envisager une sauvegarde sur bande
                    myBackup.Devices.AddDevice(_repertoireSauvegarde + myDb.Name + "_" + _horodatage + ".bak", smo.DeviceType.File);
                    try
                    {
                        myBackup.SqlBackup(myServer);
                        Console.WriteLine(myDb.Name + " sauvegardée à " + DateTime.Now.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            sc.Disconnect();
        }
 public bool fTestConnection(bool pReturnMsg = true)
 {
     try {
         Microsoft.SqlServer.Management.Common.ServerConnection vConn = new Microsoft.SqlServer.Management.Common.ServerConnection(TXT_ServerName.Text, TXT_Login.Text, TXT_Password.Text);
         Microsoft.SqlServer.Management.Smo.Server vServer            = new Microsoft.SqlServer.Management.Smo.Server(vConn);
         vConn.Connect();
         if (pReturnMsg)
         {
             if (System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName == "ar")
             {
                 MessageBox.Show("تم اختبار الوصله بنجاح", "??????");
             }
             else if (System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName == "en")
             {
                 MessageBox.Show("Test connection succeeded", "Test");
             }
         }
         return(true);
     } catch (Exception ex) {
         MessageBox.Show(ex.Message, "Error");
         return(false);
     }
 }