Check if correct database is selected in generated scripts

Related products: Software Factory

Regularly I execute scripts generated during the SF generation process in SSMS. This is all fine, unless one has the wrong database selected… This happend to me once when I wanted to execute the VIEWS script in SSMS……. with the SF database selected. One of the first things that'll be done is deleting ALL views in the current database!

As you can imagine, all kind of defects were detected in the SF afterwards, and in the end I had to rebuild the SF from the installation scripts (a restore from the previous night would result in the loss of all work that day from a couple of developers and designers). 

When the script is executed on, for example, a Navision production database all hell will break loose.

So my idea: generate a piece of code in the beginning of each script like below (BAS_DMS_WORK would be replaced by the SF with the projects database). I tested it in SSMS and it works flawlessly.

Is this something that can be built into the SF? Will it work when running the additional lines from within the SF GUI?

 

print 'Check if current schema is correct'
go

if DB_NAME() <> 'BAS_DMS_WORK'
begin
print 'Fatal error, wrong database selected for projectversion!'
set noexec on
end

print 'Ok.... All clear, let''s continue'
go

-- Rest of generated script, like dropping ALL views...... This won't execute in SSMS the wrong database is selected.
select * from work_order

select * From part_alternative where part_id = 117396

-- last line of the generated script
-- Turn execution back on; only needed in SSMS, so as to be able to run this script again in the same session.
set noexec off

               
 

Hi Henri,

Thanks for submitting your idea.

The challenge here is that, except for the database creation script, the name of the database is not used inside the scripts. This allows the scripts to be executed against different database, which is also being used by many Thinkwise developers. 

If we are going to generate a check in these scripts, this should at least be configurable. Let’s see how many votes this idea gets. 


Updated idea status NewOpen