0

I'm using DacFX in a custom installer. I am trying to override the default data and log file locations by passing in the Cmd Variables DefaultDataPath & DefaultLogPath but the database's files are still getting created in the default locations. This seems like it should be very simple and easy but even after generating the script and saving it to a file and stepping through the code I can see that the DacOptions object has the right values for the SqlCommmandVariableValues but the generated script doesn't have the values. It seems like they are ignored.

dacOptions.SqlCommandVariableValues.Add("DefaultDataPath", dataPath);
dacOptions.SqlCommandVariableValues.Add("DefaultLogPath", logPath);
webwires
  • 2,572
  • 3
  • 26
  • 44

2 Answers2

2

To put some closure on this I ended up finding a way to do this by using Deployment Contributors. An example of changing the DB location can be found in the DacFx Public Samples.

webwires
  • 2,572
  • 3
  • 26
  • 44
1

I spent a bit of time with reflector but couldn't easily see whether these are ignored or not :)

What I have done in the past is to run a script first to create the database if it didn't exist with whatever file settings I wanted then the deploy will either upgrade an empty database or upgrade the existing one.

The sql is pretty simple:

if not exists(Select * from sys.databases where name = 'XX')
begin
  create database blah blah

end

The thing with SSDT/DacFx is it gets you mostly there but you sometimes just need to give it a helping hand first :). If you can't change the default files then run a sql script first to set it up, you already have all the details and permissions you will need so you may as well make it easier on yourself.

I would also raise a connect as a bug and it might be fixed, or at least we might learn why it can't be changed.

Ed Elliott
  • 6,666
  • 17
  • 32
  • After all of the complicated "solutions" out there using Deployment Contributors, this simple approach actually solved my problem. I just run a dead simple CREATE DATABASE SQL and then proceed as normal. – jlspublic Mar 20 '18 at 00:25