© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•15mo ago•
24 replies
Jasonnn

Threading and Microsoft.Data.Sqlite

I'm using multithreading.
Each thread will make a query to a SQL Database by using a static class.

They should all use the same
SqliteConnection
SqliteConnection
connection object that is a field of
static class SqlDatabase
static class SqlDatabase
.

I feel like there is only one "opening" of the connection, and therefore there shouldn't be any problems of handling "many users" from SQLite perspective. However, I still get an error:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Data.Sqlite.SqliteConnection.RemoveCommand(SqliteCommand command)
   at Microsoft.Data.Sqlite.SqliteCommand.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Data.Sqlite.SqliteConnection.RemoveCommand(SqliteCommand command)
   at Microsoft.Data.Sqlite.SqliteCommand.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()


It looks like it tries to dispose several times the same object, and gets me a bit confused as to what is happening.
It's probably because all my threads are trying to use the same object (I explain after the MRE why I think that's the case)?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Thread and Threading
C#CC# / help
2y ago
✅ System.Data.SQLite Data Types
C#CC# / help
2y ago
❔ Microsoft.Data.SqlClient.SqlException
C#CC# / help
3y ago
✅ THREADING & CHARTS
C#CC# / help
12mo ago