SQL Script

Got a problem you cannot solve? Try here.
Lin
Posts: 29
Joined: Mon Apr 16, 2007 12:53 pm

SQL Script

Postby Lin » Tue Jun 12, 2007 4:36 pm

I am wondering if there is any good way to the location of the master databse mdf and ldf files in InstallAware.
I need this location in order to install my other database files that I need to attach.

Thanks

BrandonK
Posts: 27
Joined: Mon Jul 24, 2006 1:32 pm

Postby BrandonK » Wed Jun 13, 2007 9:45 am

Lin,

My install runs a SQL script to create the app database from scratch. It finds the path to master.mdf using the code below.

Not sure how you could do this in IA script; SQL scripting isn't my strong suit. Maybe run the first half in an IA "MS SQL Server" action and return @SQLDataPath into an IA variable?

Code: Select all

DECLARE @SQLDataPath AS NVARCHAR(256)
SET @SQLDataPath = (
   SELECT SUBSTRING(physical_name, 1, CHARINDEX('master.mdf', LOWER(physical_name)) - 1)
   FROM master.sys.master_files
   WHERE database_id = 1 AND file_id = 1
   )

EXECUTE ('
   CREATE DATABASE [YOUR_DB_NAME]
   ON (
      NAME = ''YOUR_DB_NAME'',
      FILENAME = ''' + @SQLDataPath + 'YOUR_DB_NAME.mdf'',
      SIZE = 3072KB ,
      MAXSIZE = UNLIMITED,
      FILEGROWTH = 10%
      )
   LOG ON (
      NAME = ''YOUR_DB_NAME Log'',
      FILENAME = ''' + @SQLDataPath + 'YOUR_DB_NAME.ldf'',
      SIZE = 1024KB ,
      MAXSIZE = 1GB , FILEGROWTH = 10%
      )
   COLLATE SQL_Latin1_General_CP1_CI_AS
   ')
GO


Hope this helps,
Brandon


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 125 guests