Backup databases programatically.

Hello

1. Sql Express supports SMO
2. If so How can I make a backup of a database programatically


Thanks


Answer this question

Backup databases programatically.

  • Jasaldrich

    Thanks   

  • victoravilanet

    SQL express does indeed support SMO.

  • pink_flower4love

    You do know that you can overload the Server instantiation to direct it to the server you want to connect to, don't you

    Example:

    Dim srv As Server
    srv = New Server("MyLapTop\Express")

    In VB.Net you can also set the property in the ServerConnection object:

    Dim srv As Server
    Dim srvConn As ServerConnection

    srv = New Server

    srvConn = srv.ConnectionContext
    srvConn.LoginSecure = True
    srvConn.ServerInstance = "MyLapTop\Express"

    Either one should work for you.



  • SHAILESH KUMAR PANDEY

    I am using the example code with minor modifications and can't get around the unable to connect error.... Has anyone run into this issue I have tried everything I can think of at this point and it just won't connect to the local instance.


  • Norman37050

    I found how do it.  but still waiting for the other answers.

    Its so easy, I love Microsoft Tools.

    using Microsoft.SqlServer.Management.Smo;



    namespace SMOTest
    {
        class Program
        {
         static void Main()
         {
          Server svr = new Server();
          Backup bkp = new Backup();
          bkp.Action = BackupActionType.Database;
          bkp.Database = "AdventureWorks";
          bkp.DeviceType = DeviceType.File;
          bkp.Devices.Add(@"c:\SMOTest.bak");
          bkp.SqlBackup(svr);
         }
       }
    }

     



  • Backup databases programatically.