Comments (3)
@jhinder yes, as long as different DbContext instances are being used, you shouldn't get this exception. However, I can't really tell you what you're doing specifically in your code that triggers this - definitely not from the two snippets posted above (and no stack trace); it's always a good idea to post a fully runnable, minimal project or code sample, rather than a partial set of snippets - there's very frequently something hiding in unposted code that explains the problem. I'd take a very careful look at your DbContext usages - of course as a function of the exception stack trace - and try to see where concurrent usage may be happening.
from efcore.pg.
OK, so I've continued debugging this a bit and I guess I solved it.
Previously, we would export a NpgsqlConnection
(initialized with our connection string) instance with a service type of DbConnection
and a lifetime of Singleton. The optionsAction
of AddDbContext
would retrieve that instance from the supplied IServiceProvider
and pass it as the first argument to UseNpgsql
.
I've now simplified that a bit so that the optionsAction
now only retrieves the connection string (via a simple custom type called ConnectionStringProvider
whose only method returns the connection string, and that type is exported into the DI as a singleton because it needs IConfiguration
) and passes that to UseNpgsql
.
I guess the former scenario (multiple scoped services operate on a singleton DbConnection
) is unsupported because Npgsql does something in the way of connection management?
Anyway, I can now throw a hundred parallel queries against the database with the code above and I can run the infinite request loop as well, both seem to work just fine.
from efcore.pg.
I guess the former scenario (multiple scoped services operate on a singleton DbConnection) is unsupported because Npgsql does something in the way of connection management?
Well, a DbConnection represents an actual single physical connection to the database - it's very much not usable concurrently from multiple threads (since the same TCP connection can't be used simultaneously...). I'm not sure what the idea was behind having a single DbConnection previously, but it's definitely not a typical or recommended way to do things, and would indeed lead to NpgsqlOperationInProgressException very quickly.
BTW as an alternative to passing in the connection string, you may want to look at NpgsqlDataSource (see the Npgsql docs).
I'll go ahead and close this as everything seems clear and there doesn't seem to be an issue with Npgsql.
from efcore.pg.
Related Issues (20)
- migration on changed includedPropertyNames for IsGeneratedTsVectorColumn creates up/down code in wrong order
- "integer out of range" error when using date_part in where clause with another conditional HOT 1
- Writing values of 'NpgsqlTypes.NpgsqlRange`1[[System.TimeSpan, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]][]' is not supported for parameters having NpgsqlDbType '-2147483608'. HOT 3
- Error : ''failure to parse near offset 7489. expected an ascii digit,, when runing from EF core .Net 8 HOT 2
- Error : ''failure to parse near offset 7489. expected an ascii digit,, when runing from EF core .Net 8 HOT 5
- Feature Request: protect connection string literal in memory HOT 2
- Support value conversion with generated properties HOT 4
- Map User Defined Function return table value with parameter timestamp without time zone HOT 3
- Cannot rename system column "xmin" HOT 3
- Reverse engineering for view does not preserve nullability of columns HOT 4
- ISSUE: A PostgreSQL type with the oid '0' was not found in the current database info
- SQL translation error when using LEFT JOIN in `Where` HOT 6
- Upgrading INpgsqlArrayConverter to PrimitiveCollection
- EF.Functions support for json_array_length HOT 2
- Npgsql.PostgresException (0x80004005): 42883: function st_contains(deployment.geometry, deployment.geometry) does not exist HOT 4
- ISet<EnumType>.Contains() does not translate in EF Core 8 HOT 1
- EF.Functions.JsonContains() occurs issue after upgrade to .net 8
- Querying a DateTimeOffset in a jsonb as JsonDocument fails with InvalidCastException
- Translation from Contains to strpos leads to extremely slow queries HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efcore.pg.