Restoring a BCM database from SQL .mdf and .ldf files (Windows Vista or XP)

If you need to restore a BCM database from the .mdf and .ldf SQL database files, you can use the following script to attach the SQL database.

Be sure to install the latest version of BCM and all service packs before running this script, since BCM will not connect to databases that were created using newer versions of BCM.

Copy the text below into Notepad and follow the instructions.  Let me know if you have any questions about this. 
~ Clinton Ford

REM Restore a BCM database from the SQL .mdf and .ldf files (Windows Vista or XP)
REM --------------------------------------------------------------------------------
REM Instructions
REM 1.) Install and configure BCM on the destination computer.
REM 2.) Copy your backup .mdf and .ldf files into the BCM database folder.
REM      To do this, click Start | Run, then enter the following text into the text box and click "OK":
REM           %LOCALAPPDATA%\Microsoft\Business Contact Manager\
REM     NOTE: You might need to rename your .mdf and .ldf files if a pair of files with the same name already exists
REM 3.) Now, modify this script in Notepad by doing the following:
REM 4.) Press CTRL+H in Notepad to open the Replace dialog
REM 5.) Type <BACKED_UP_DATABASE_NAME> in the "Find what" box
REM 6.) In the "Replace with" box, enter the name of the backed up BCM database (without the .mdf file extension)
REM 7.) Save this script to your Desktop as RestoreDB.cmd
REM 8.) Run this script by double-clicking on the RestoreDB.cmd file on your Desktop
REM 9.) From the main Outlook window, select "Business Contact Manager | Database Tools | Create or Select a Database..."
REM 10.) Select your backed up database from the drop-down list and click "Next"

"c:\program files\microsoft sql server\90\tools\binn\sqlcmd.exe" -b -E -S .\MSSMLBIZ -Q "EXEC sp_attach_db @dbname = '<BACKED_UP_DATABASE_NAME>', @filename1 = '%LOCALAPPDATA%\Microsoft\Business Contact Manager\<BACKED_UP_DATABASE_NAME>.mdf', @filename2 = '%LOCALAPPDATA%\Microsoft\Business Contact Manager\<BACKED_UP_DATABASE_NAME>.ldf';">>"%LOCALAPPDATA%\Microsoft\Business Contact Manager\<BACKED_UP_DATABASE_NAME>_RestoreResult.txt"
@ECHO Attach DB Returned:%ERRORLEVEL%>>"%LOCALAPPDATA%\Microsoft\Business Contact Manager\<BACKED_UP_DATABASE_NAME>_RestoreResult.txt"
@ECHO Attach DB Returned:%ERRORLEVEL%