How to install an existing SQL-Server database?

Got a problem you cannot solve? Try here.
folo77
Posts: 4
Joined: Wed Aug 01, 2007 6:42 am

How to install an existing SQL-Server database?

Postby folo77 » Tue Oct 16, 2007 9:28 am

Hello,

I'm using IA V6.22 and I want my Setup to install an existing SQL-Server Database (mdf/ldf-file are present) to a local SQL-Server 2005 database system. I have already managed to create a new database by integrating a new (empty) MS SQL Script and checking "Create database if absent". Then I tried to generate a SQL-Script that contains the whole database layout (tables...) and the whole content, but that seems a little bit too complex and inefficient to me.

Is there an easier way to add an existing SQL-Server Database to a (local) SQL-Server using the IA Installer, e.g. by copying and somehow adding the mdf/ldf-files to the (locally installed) SQL-Server instead of transforming the whole database into a script?

Thanks in advance...

Alex_Ronquillo
Site Admin
Posts: 364
Joined: Mon Jul 30, 2007 11:51 am
Location: USA
Contact:

Postby Alex_Ronquillo » Wed Oct 17, 2007 11:48 am

You can restore your DB from the mdf/ldf files with a restore script. Here is an example:

Code: Select all

RESTORE DATABASE [DBName] FROM DISK = '$SUPPORTDIR$DBName.BAK' WITH REPLACE, MOVE 'DBName_Data' TO '$Path$\\DATA\\DBName.MDF', MOVE 'DBName_Log' TO '$Path$\\DATA\\DBName.LDF'
Alejandro Ronquillo
InstallAware
Home of The Next Generation MSI Installer
Get your free copy today - http://www.installaware.com/

folo77
Posts: 4
Joined: Wed Aug 01, 2007 6:42 am

Postby folo77 » Thu Oct 18, 2007 4:58 am

Thank you! That was exactly what I needed.

I created the DBName.BAK file with the backup function of the SQL Server Management Console. Then I added it to the Support Files in IA and completed the script as follows, so that I don't overwrite any existing database:

Code: Select all

 IF NOT EXISTS(SELECT * FROM sys.databases where name = 'DBName')
RESTORE DATABASE [DBName] FROM DISK = '$SUPPORTDIR$DBName.BAK' WITH REPLACE, MOVE 'DBName_Data' TO '$Path$\\DATA\\DBName.MDF', MOVE 'DBName_Log' TO '$Path$\\DATA\\DBName.LDF'


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 106 guests