Replies: 2 comments 1 reply
-
I found myself with a similar requirement. I figured there'd be an active connection / transaction, and I could retrieve the database name from the environment to work around the issue using something like this:
Unfortunately, this doesn't work, as alter database statements aren't allowed in multi-statement transactions. Given the transactionality of migrations is one of their great strengths, I ended up just accepting that this logic was probably a poor fit for a migration. |
Beta Was this translation helpful? Give feedback.
-
I'm sorry I never responded to this. I use Execute.WithConnection for these things. You just have to bare in mind that Execute.WithConnection flows differently than other migrations since it is a promise to execute something. But you can basically stack Execute.WithConnection commands and thread them together. I create a separate layer for this stuff so it's not directly in my migrations and is a re-usable library that just uses a SqlConnection or DbConnection, so that I can re-use this stuff in many different projects. |
Beta Was this translation helpful? Give feedback.
-
I am planning to set read committed snapshot isolation level on mssql db via migrator by adding the following line:
The problem is I don't have a database name. I can only parse the connection string (see example bellow):
In NHibernate having a session I can easlily use the following:
But inside the migrator context I don't have a NH session nor database name.
Is there a way to get the database name besides manually parsing the connection string?
Beta Was this translation helpful? Give feedback.
All reactions