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.

Can I use SqliteCreateDatabaseIfNotExists within an external transaction?

See original GitHub issue

I want to use SqliteCreateDatabaseIfNotExists within a transaction, but I can’t because SqliteInitializerBase.InitializeDatabase() creates one while execution. Is there any way to use an external transaction with the initializer?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
msallincommented, Jan 26, 2019

Thank you for your PR. As I look at this, I ask myself whether the first transaction is necessary. The first transaction is to ensure the atomicity of the Database creation. Inside this transaction the SqliteDatabaseCreator is called. There I wrote the following code: db.ExecuteSqlCommand(TransactionalBehavior.EnsureTransaction, sql); That this query will always be executed as transaction (either as a new one or the existing will be used). That means also, that your code will not work (there will always be a transaction, which is IMHO how it should be).

The solution here is simply to remove the first transaction creation in the initializer. -> The query will be executed always inside a transaction but you can specify your own.

Then there is the second part, the seeding of the data. There its also not necessary to have explicitly a transaction because SaveChanges is only called once, which means there is an implicit transaction.

Therefore, I’ll reject your PR and just delete the unnecessary code. It would be great if you can test your use case with it.

0reactions
msallincommented, Jan 28, 2019

Version 1.5.2 published. NuGet will list it within one hour.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQLiteDatabase nested transaction and workaround
The nested transaction cannot be rolled back itself, because it does not exist apart from the outside transaction.
Read more >
SqLite Transactions:Yes, but Ambient Transactions:No?
You currently cannot use ambient System.Transactions.Transaction over multiple data sources (distributed transaction), regardless of database.
Read more >
Statements outside of explicit transactions in SQLite
So I tried a test: In one thread, I ran a SELECT statement, but in between retrieving rows (2 at a time) I...
Read more >
Transactions - Microsoft.Data.Sqlite
Transactions let you group multiple SQL statements into a single unit of work that is committed to the database as one atomic unit....
Read more >
SQLite Transaction Explained By Practical Examples
Learn how to deal with SQLite transactions by using the BEGIN TRANSACTION, COMMIT, and ROLLBACK statements to control transactions.
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