question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CREATE DATABASE in a migration

See original GitHub issue

Will appreciate the help with the next issue- I’m working with .Net and trying to run the next migration (on MSBuild mode): EXEC sp_executesql N'CREATE DATABASE evolveshared'

At the end of the build I’m getting the next error: ‘EvolveException: Error executing script: V01__evolveSharedCreateDataBase.sql. CREATE DATABASE statement not allowed within multi-statement transaction. Sql query: EXEC sp_executesql N’CREATE DATABASE evolveshared’ CREATE DATABASE statement not allowed within multi-statement transaction.’

When I run the same migration on SQL Management Tool (2017) it works fine and creating the asked DB.

When I’m changing the migration to the next one: COMMIT TRAN; GO EXEC sp_executesql N'CREATE DATABASE evolveshared' The DB is created but I’m getting a different error: ‘EvolveException: Error executing script: V01__evolveSharedCreateDataBase.sql. This SqlTransaction has completed; it is no longer usable.’

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
lecailloncommented, Nov 5, 2019

Addressed by #150

Evolve 2.4.0 will support SQL statements like CREATE DATABASE in special migrations that execute outside of a transaction. To use this feature add this comment in the first line of your migration script: evolve-tx-off.

-- evolve-tx-off
create database evolveshared
0reactions
RobinHiQcommented, Mar 13, 2023

Addressed by #150 Evolve 2.4.0 will support SQL statements like CREATE DATABASE in special migrations that execute outside of a transaction. To use this feature add this comment in the first line of your migration script: evolve-tx-off.

-- evolve-tx-off
create database evolveshared

while runnig above script getting an error that [dbname] is not exist. Evolve version is 3.0.0

Did you figure this out? Getting the same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create database using code first migrations?
2 Answers 2 · Delete your database from within SQL Server Object Explorer · Delete all your existing migrations from within the Migrations...
Read more >
Migrations Overview - EF Core
Install the tools · Create your first migration · Create your database and schema · Evolving your model · Excluding parts of your...
Read more >
Code-Based Migration in Entity Framework 6
Update-Database: Executes the last migration file created by the Add-Migration command and applies changes to the database schema.
Read more >
Database Migration: What It Is and How to Do It
Granular Changes Are Generated as Individual Scripted Files · Database Migration Scripts Are Tool-Dependent · Option 1: Use a Framework/Language- ...
Read more >
Code First Migrations with an existing database - EF6
Step 1: Create a model. Your first step will be to create a Code First model that targets your existing database. · Step...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found