Friday, February 17, 2012

Create Database Script - Help Required

Hi,

I have a Database.sql script file that creates my application database (Malibu). My question is how do I get around the problem of the hard coded FILENAME as shown below...


CREATE DATABASE [Malibu] ON (NAME = N'Malibu_Data', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\Data\Malibu_Data.MDF' , SIZE = 4, FILEGROWTH = 10%) LOG ON (NAME = N'Malibu_Log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\Data\Malibu_Log.LDF' , SIZE = 1, FILEGROWTH = 10%)

If this path does not exist on the clients PC - the script will fail.

Any suggestions appreciated.

Thanks.

Steve.Build the script as a string and then execute the string.

Declare @.strScript as varchar(5000)

SET @.strScript = 'CREATE DATABASE [Malibu] FILENAME = ' + @.thecorrectpathhereasavariable + '\Malibu_Data.MDF' '

Exec(@.strScript)

How you actually determine the path I do not know, but you can variableize the script as the above example.|||Thanks Wes,

I currently run the script from a batch file using OSQL, however, the way things are heading with .Net, I guess I should look at doing it in VB code.

Steve.|||The code I posted was T-SQL code.

No comments:

Post a Comment