Hello,
I am running a SQL script in the installer that creates a new database. I would like a user to receive a message saying that the database already exists and that they need to re-run the installer and provide a different name.
The way I was thinking to do it was to provide a raiserror in the sql script with a return statement. But the script continues and I receive an exception that TABLE ... already exists . Later tried with IF condition. Same script stops execution in SQL management studio but in the installer not and continues to create table. here is a sample:
/*
**********************************************
CHECK IF THE DATABASE ALREADY EXISTS
**********************************************
*/
DECLARE @bContinue BIT;
SET @bContinue = 1
IF EXISTS(SELECT * FROM sys.databases WHERE name = '#DBNAME_PROP#')
BEGIN
RAISERROR ('Database ''#DBNAME_PROP#'' already exists. Restart the setup and provide a different database name.',16,1)
SET @bContinue = 0
END
IF @bContinue = 0
RETURN;
....
Create Tables follows
----------------------------------------------------
Am I on the right track and just need to modify my SQL script or is there a better way to achieve what I am trying to do ?
Thank you.
Kissack
FOLLOW US
Get the latest news in Application Packaging