Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL server: How to get backup file information using SMO

SQL server: How to get backup file information using SMO

Scheduled Pinned Locked Moved Database
databasesql-serversysadmintutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    w14243
    wrote on last edited by
    #1

    SQL server 2014/2016, SMO. Using SMO to backup a databse to 'D:\SQLBK\Mon\dbc.bak' on server: public int BackupDB(string serverName, string dbName, string backupFolder) { Server oServer = new Server(new ServerConnection(ServerName)); Backup oBackup = new Backup(); oBackup.Action = BackupActionType.Database; oBackup.Database = dbName; oBackup.Initialize = false; oBackup.Incremental = false; oBackup.LogTruncation = BackupTruncateLogType.Truncate; string sBackupFilename = Path.Combine(backupFolder, dbName + ".bak"); oBackup.Devices.AddDevice(sBackupFilename, DeviceType.File); oBackup.SqlBackup(oServer); return 0; } How to get original database information from backup file 'D:\SQLBK\Mon\dbc.bak' through SMO? e.g. database name.

    L 1 Reply Last reply
    0
    • W w14243

      SQL server 2014/2016, SMO. Using SMO to backup a databse to 'D:\SQLBK\Mon\dbc.bak' on server: public int BackupDB(string serverName, string dbName, string backupFolder) { Server oServer = new Server(new ServerConnection(ServerName)); Backup oBackup = new Backup(); oBackup.Action = BackupActionType.Database; oBackup.Database = dbName; oBackup.Initialize = false; oBackup.Incremental = false; oBackup.LogTruncation = BackupTruncateLogType.Truncate; string sBackupFilename = Path.Combine(backupFolder, dbName + ".bak"); oBackup.Devices.AddDevice(sBackupFilename, DeviceType.File); oBackup.SqlBackup(oServer); return 0; } How to get original database information from backup file 'D:\SQLBK\Mon\dbc.bak' through SMO? e.g. database name.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      w14243 wrote:

      How to get original database information from backup file 'D:\SQLBK\Mon\dbc.bak' through SMO? e.g. database name.

      The database-name is not part of the backup. You backup the data, not meta-data on the file.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups