SQLDMO: howto obtain logical file names from a BAK file

From: Rocio (rocio.katsanis_at_softwareservices.net)
Date: 03/11/04


Date: 11 Mar 2004 10:04:30 -0800

what, how, when does a logical file name is determine for a database?
If I am restoring a db from Enterprise Manager, under the Options tab,
after I configured the device to restore from (a file), I can see the
logical filenames of both, the mdf and the ldf files.

Now, I am automating all this process into code, and the SQL-DMO
object that restores a db from a file, requires to know the logical
file names for both the mdf and ldf files, specially if I am restoring
from a BAK file that was created in another server, under a specific
folder. For the moment I am hard-coding these values since this
program will (hopefully) always run to restore the same database at
the clients site. But is it possible the logical file name could
change?
The best way would be for the program to 'read' the logical names from
the actual BAK file, but I haven't figured that out yet. Any ideas on
how to do this?

My code goes:

Private oRestore As SQLDMO.Restore2

oRestore.Action = SQLDMORestore_Database
oRestore.database = database
oRestore.Files = filename
oRestore.ReplaceDatabase = True
oRestore.RelocateFiles = "[This_DB_Logical_FIlename_dat]" & "," & _
        "[C:\Program Files\Microsoft SQL Server\MSSQL\Data\" &
database & ".mdf]" & "," & _
        "[This_DB_Logical_FIlename_log]" & "," & _
        "[C:\Program Files\Microsoft SQL Server\MSSQL\Data\" &
database & ".ldf]"

oRestore.SQLRestore oSQLServer 'restores the db

where database, filename are strings passed to this function.
database is the name for my database, and filename is the name
(including the full pathname) of the bak file to restore.
In this case the name of the database is not the same as the logical
file name.

I need to specify oRestore.RelocateFiles in my code becasue the BAK
file comes from another SQL server, was created in another folder, so
the default values will point to the location on that server. When I
am restoring in another server, another computer.



Relevant Pages

  • Re: sbs2003 and sharepoint
    ... The process described in the link does not refer to restoring to a different server. ... Your first step would be to have a new companyweb on an SBS server and then restore to that the files in from the databases you backed up. ... >> database the other one is the configuration database. ...
    (microsoft.public.windows.server.sbs)
  • Re: Backup and restore question
    ... If you are referring to the 2000 version then archiving and restoring ... the database from one server to the other should work fine as long as ...
    (microsoft.public.sqlserver.olap)
  • Re: Restore Content Database problem
    ... I found that by having the exact same security as I did before hand ... The new server was not put onto a domain but once it ... I have spent basically the whole day reading about restoring the ... content database in WSS but I still can't seem to get it working. ...
    (microsoft.public.sharepoint.windowsservices)
  • Re: Desperate cry for help (Disater recovery)
    ... Backing Up and Restoring Windows Small Business Server 2003 ... > data is, including exchange database. ...
    (microsoft.public.windows.server.sbs)
  • Re: Restore SharePoint Server backup to New Server
    ... But here the problem is after restoring the database I am ... and configure SharePoint on the new server it will create a new config DB. ... I am having a problem while restoring the backup from old server to a new ...
    (microsoft.public.sharepoint.portalserver)