1

I'm using DbUp to migrate my SQL Server database. I've implemented this in a console application, that accepts the connection string. If I run this against my local SQL Server database, it works. If I run it against an Azure SQL database, it works as well.

However, if I run it against a LocalDb database that was created on the fly in my tests, I get an exception.

The line on which the exception occurs is:

 EnsureDatabase.For.SqlDatabase(connectionString);

and the connection string parameters contains:

 Data Source=(LocalDB)\MSSQLLocalDB;AttachDBFileName=C:\Projects\Prim\mgp\Prim.Mgp.Infrastructure.DataAccessTests\bin\Debug\netcoreapp2.2\Data\ccf243baa63eb4ea258b0155.mdf;Initial Catalog=ccf243baa63eb4ea258b0155;Integrated Security=True;MultipleActiveResultSets=True;

The exception is:

System.Data.SqlClient.SqlException: 'Database 'C:\Users\ludwigs\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\master.mdf' already exists. Choose a different database name. Cannot attach the file 'C:\Projects\Prim\mgp\Prim.Mgp.Infrastructure.DataAccessTests\bin\Debug\netcoreapp2.2\Data\ccf243baa63eb4ea258b0155.mdf' as database 'master'.'

...which is a bit strange, because it mentioning a different database than I specified in the connection string.

Does anyone have a clue what I might be doing wrong?

PS: if I remove the troublesome line of code , I can query my database without problems.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
L-Four
  • 13,345
  • 9
  • 65
  • 109

1 Answers1

0

There is a problem with the AttachDBFileName in the connection string, try to test with this connection string. And DBUp run the master so it can create the database using Ensure Database.For.Sql Database,

<connectionStrings>
 <add name="Database" connectionString="Server=.;Database=Migrations_DbUp;Integrated Security=true"/>
</connectionStrings>
Erik
  • 13
  • 3