I followed the documentation example to extend my autoquery endpoint to change the descending order to descending nulls last like so:
public class QueryServices : Service
{
public IAutoQueryDb AutoQuery { get; set; }
public object Any(QueryDomains dto)
{
var normalDescendingOrder = new string[]
{
"domainName",
};
var q = AutoQuery.CreateQuery(dto, Request.GetRequestParams());
if (!normalDescendingOrder.Contains(dto.OrderByDesc))
{
q.OrderByExpression = q.OrderByExpression.Replace("DESC", "DESC NULLS LAST");
}
return AutoQuery.Execute(dto, q);
}
}
(btw there is small typo in example code in docs. It passes “request” when it should pass “dto”).
This works fine but if there are 2 requests within a short space of each other then AutoQuery.Execute(dto, q)
throws this or similar exception:
A command is already in progress: SELECT COUNT(*) "COUNT(*)"
FROM "domain_search_view"
WHERE "domain_search_view"."tf" > :0
I found thread that said it is because the IDbConnection is not threadsafe but how do I create separate connection so I can handle more than one request at a time? IAutoQueryDb is being injected so I am not sure exactly how this is supposed to be done. I intend the code to be used by multiple people at the same time so it will have to be able to handle this.
What is best way to fix this?
This is how I register IDbConnectonFactory in startup:
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(
AppSettings.Get<string>("development:pgConString"),
PostgreSqlDialect.Provider));
Edit:
I also get this exception:
Npgsql.NpgsqlException: ‘Exception while reading from stream’
IOException: Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall.
SocketException: A blocking operation was interrupted by a call to WSACancelBlockingCall
I can re-create it when doing a query that takes long time to complete