Recently migrated from MSSQL to Postgre. For some reason 1st query request now takes a lot of time and times out. Then every following requests are being processed as per usual. If no requests are being sent to DB for ~5 minutes, then timeout for following request happens again.
I have tried different EF queries, so it's not like only specific query times it out.
DbContext configuration
services.AddDbContext<ApplicationContext>(options =>
options.UseNpgsql(
Configuration.GetConnectionString("DefaultConnection"),
npgslOptions => npgslOptions.MigrationsHistoryTable("__efmigrationshistory", Constants.DB_SCHEMA)
.EnableRetryOnFailure()
) production
.EnableDetailedErrors(true)
.EnableSensitiveDataLogging(true)
.ReplaceService<IHistoryRepository, LoweredCaseMigrationHistoryRepository>()
.UseSnakeCaseNamingConvention());
Connection string
"Host=hostname.domain.local;Port=5432;Database=DatabaseName;Username=usrn;Password=pwd;"
Error received
2022-06-08 11:37:54.670 +03:00 [ERR] An error occurred using the connection to database 'DbName' on server ''.
2022-06-08 11:37:54.697 +03:00 [INF] A transient exception occurred during execution. The operation will be retried after 0ms.
System.TimeoutException: The operation has timed out.
at Npgsql.Util.NpgsqlTimeout.Check()
at Npgsql.Util.NpgsqlTimeout.CheckAndGetTimeLeft()
at Npgsql.Util.NpgsqlTimeout.CheckAndApply(NpgsqlConnector connector)
at Npgsql.Internal.NpgsqlConnector.<Open>g__OpenCore|191_1(NpgsqlConnector conn, SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken, Boolean isFirstAttempt)
at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.ConnectorPool.OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.ConnectorPool.<Get>g__RentAsync|28_0(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnection.<Open>g__OpenAsync|45_0(Boolean async, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass33_0`2.<<ExecuteAsync>b__0>d.MoveNext()
Related
I just updated Visual Studio from 2022 Preview 2 to Preview 3. My MAUI app calls REST services that I host in Azure, i.e. on a azurewebsites.net domain. When I upgraded to Preview 3, it also updated/reinstalled mobile SDKs for Android and IOS.
Everything is still working on the Android simulator, but when I try the app on an IOS device, it fails now when trying to connect to my REST service hosted in Azure. The error it gives is "The SSL connection could not be established, see inner exception.".
The InnerException is a System.EntryPointNotFoundException, and the Message associated with it is "SystemNative_GetDefaultTimeZone". I've not been able to find this error reported elsewhere, but my whole IOS apps is dead in the water. Has anyone else seen this error after upgrading to Preview 3, or in any other circumstances and know exactly what needs to be changed?
Here is the full error stack:
{System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.EntryPointNotFoundException: SystemNative_GetDefaultTimeZone
at System.TimeZoneInfo.TryGetLocalTzFile(Byte[]& rawData, String& id)
at System.TimeZoneInfo.GetLocalTimeZoneFromTzFile()
at System.TimeZoneInfo.GetLocalTimeZoneCore()
at System.TimeZoneInfo.GetLocalTimeZone(CachedData cachedData)
at System.TimeZoneInfo.CachedData.CreateLocal()
at System.TimeZoneInfo.CachedData.get_Local()
at System.TimeZoneInfo.get_Local()
at System.TimeZoneInfo.GetDateTimeNowUtcOffsetFromUtc(DateTime time, Boolean& isAmbiguousLocalDst)
at System.DateTime.get_Now()
at System.Security.Cryptography.X509Certificates.X509ChainPolicy.Reset()
at System.Security.Cryptography.X509Certificates.X509ChainPolicy..ctor()
at System.Security.Cryptography.X509Certificates.X509Chain.get_ChainPolicy()
at System.Net.Security.SecureChannel.VerifyRemoteCertificate(RemoteCertificateValidationCallback remoteCertValidationCallback, SslCertificateTrust trust, ProtocolToken& alertToken, SslPolicyErrors& sslPolicyErrors, X509ChainStatusFlags& chainStatus)
at System.Net.Security.SslStream.CompleteHandshake(ProtocolToken& alertToken, SslPolicyErrors& sslPolicyErrors, X509ChainStatusFlags& chainStatus)
at System.Net.Security.SslStream.CompleteHandshake(SslAuthenticationOptions sslAuthenticationOptions)
at System.Net.Security.SslStream.<ForceAuthenticationAsync>d__175`1[[System.Net.Security.AsyncReadWriteAdapter, System.Net.Security, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage request)
at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.<WaitWithCancellationAsync>d__1[[System.Net.Http.HttpConnection, System.Net.Http, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()
at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at MyApp.Utilities.TokenHelper.Authenticate(String authState) in C:\Users\spesc\Documents\Visual Studio 2019\Projects\MyApp\Utilties\TokenHelper.cs:line 85}
I'm answering this because I think it's likely that other people may hit this same error. In researching the Exception type (EntryPointNotFoundException), it described scenarios such as a mismatched DLL assembly. So to fix this, I did the following:
Clean the solution
Delete everything out of the obj folder
Delete everything out of the debug folder
Run and deploy again
After doing so, the app started working on IOS devices.
I'm new to Squidex and MongoDB and I'm trying to set up Squidex within an Azure App Service following this guide:
https://docs.squidex.io/01-getting-started/installation/install-azure
I've completed the setup without issues and I'm able to connect to my MongoDb instance locally, without issue using the user I've configured as an administrator within my Squidex Mongo Database.
However, my App Service fails to start with the following error:
2021-02-18T00:45:27.806844798Z Unhandled exception. Squidex.Hosting.Configuration.ConfigurationException: MongoDb connection failed to connect to database Squidex.
2021-02-18T00:45:27.806899798Z
2021-02-18T00:45:27.806905498Z ---> MongoDB.Driver.MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1.
2021-02-18T00:45:27.806910099Z ---> MongoDB.Driver.MongoCommandException: Command saslStart failed: Authentication failed..
2021-02-18T00:45:27.806914099Z at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.ProcessReply(ConnectionId connectionId, ReplyMessage`1 reply)
2021-02-18T00:45:27.806918499Z at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken)
2021-02-18T00:45:27.806931099Z at MongoDB.Driver.Core.Authentication.SaslAuthenticator.AuthenticateAsync(IConnection connection, ConnectionDescription description, CancellationToken cancellationToken)
2021-02-18T00:45:27.806935599Z --- End of inner exception stack trace ---
2021-02-18T00:45:27.806948099Z at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
2021-02-18T00:45:27.806952999Z at MongoDB.Driver.Core.Servers.Server.GetChannelAsync(CancellationToken cancellationToken)
2021-02-18T00:45:27.806956899Z at MongoDB.Driver.Core.Operations.CreateIndexesOperation.ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
2021-02-18T00:45:27.806960799Z at MongoDB.Driver.OperationExecutor.ExecuteWriteOperationAsync[TResult](IWriteBinding binding, IWriteOperation`1 operation, CancellationToken cancellationToken)
2021-02-18T00:45:27.806964699Z at MongoDB.Driver.MongoCollectionImpl`1.ExecuteWriteOperationAsync[TResult](IClientSessionHandle session, IWriteOperation`1 operation, CancellationToken cancellationToken)
2021-02-18T00:45:27.806970799Z at MongoDB.Driver.MongoCollectionImpl`1.MongoIndexManager.CreateManyAsync(IClientSessionHandle session, IEnumerable`1 models, CreateManyIndexesOptions options, CancellationToken cancellationToken)
2021-02-18T00:45:27.806974799Z at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)
2021-02-18T00:45:27.806978699Z at Squidex.Infrastructure.MongoDb.MongoRepositoryBase`1.InitializeAsync(CancellationToken ct) in /src/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs:line 113
2021-02-18T00:45:27.806984099Z --- End of inner exception stack trace ---
2021-02-18T00:45:27.806987899Z at Squidex.Infrastructure.MongoDb.MongoRepositoryBase`1.InitializeAsync(CancellationToken ct) in /src/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs:line 119
2021-02-18T00:45:27.806991899Z at Squidex.Hosting.InitializerHost.StartAsync(CancellationToken cancellationToken)
2021-02-18T00:45:27.806995599Z at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
2021-02-18T00:45:27.806999399Z at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
2021-02-18T00:45:27.807003099Z at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
2021-02-18T00:45:27.807006899Z at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
2021-02-18T00:45:27.807930204Z at Squidex.Program.Main(String[] args) in /src/src/Squidex/Program.cs:line 22
I'm using a connection string similar to this within the EVENTSTORE__MONGODB__CONFIGURATION and STORE__MONGODB__CONFIGURATION application settings in my App Service:
mongodb://[USER_NAME]:[PASSWORD]#[MONGO_IP]:27017
I was able to resolve the issue, Squidex requires the connection string include the authSource as well. If you encounter this issue, add ?authSource=[DatabaseName] to your connection string. In my case, this is what was required:
mongodb://[USER_NAME]:[PASSWORD]#[MONGO_IP]:27017?authSource=Squidex
I have a serverless application using the following stack.
- AWS API Gateway
- Proxied to Lambda functions running .NET Core using Entity Framework Core for PostgreSQL to do reads or writes to PostgreSQL Aurora.
Every so often - without code changes or any infrastructure or other changes, I get the following error on a database query/savechanges().
System.InvalidOperationException: An exception has been raised that is likely due to a transient failure.
---> Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details.
---> Npgsql.NpgsqlException (0x80004005): Exception while reading from stream
---> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer.
---> System.Net.Sockets.SocketException (104): Connection reset by peer
--- End of inner exception stack trace ---
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
at System.Net.Security.SslStream.<FillBufferAsync>g__InternalFillBufferAsync|215_0[TReadAdapter](TReadAdapter adap, ValueTask`1 task, Int32 min, Int32 initial)
at System.Net.Security.SslStream.ReadAsyncInternal[TReadAdapter](TReadAdapter adapter, Memory`1 buffer)
at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass34_0.<<Ensure>g__EnsureLong|0>d.MoveNext()
at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass34_0.<<Ensure>g__EnsureLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
at Npgsql.NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList`1 entriesToSave, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(DbContext _, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at LCSApi.Functions.PostCustomerProxyResponse(APIGatewayProxyRequest request, ILambdaContext context) in C:\Users\JMatson\source\repos\LCSSolution\testapi\Function.cs:line 426
I can't find a reason for this. I am running a fairly vanilla database first scaffolding of the database. The only thing that seems to cause it to occur is when I haven't invoked my API method for a few minutes. The first call has this error, then any done after work fine. They continue to work fine unless I don't invoke for a few minutes.
I found a nice article in http://www.loresoft.com/Generate-ASP-NET-Web-API. I've read and test it with the SQL Server database with success. Now, I want to change the database engine into PostgreSQL, I've migrated the database from SQL Server into PostgreSQL.
But, When I am executing:
efg generate -c ""Host=localhost;Username=admin;Database=dbTest;Password=admin;Persist Security Info=True""
The console showing me:
17:18:04 W Option file not found: generation.yml
17:18:04 I Using default options
17:18:04 D Creating database model factory for: SqlServer
17:18:04 I Loading database model ...
17:18:04 F Host terminated unexpectedly
System.ArgumentException: Keyword not supported: 'host'.
at Microsoft.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey)
at Microsoft.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms)
at Microsoft.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
at Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
at Microsoft.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
at Microsoft.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(String connectionString, DatabaseModelFactoryOptions options)
at EntityFrameworkCore.Generator.CodeGenerator.GetDatabaseModel(IDatabaseModelFactory factory) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator.Core\CodeGenerator.cs:line 371
at EntityFrameworkCore.Generator.CodeGenerator.Generate(GeneratorOptions options) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator.Core\CodeGenerator.cs:line 40
at EntityFrameworkCore.Generator.GenerateCommand.OnExecute(CommandLineApplication application) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator\GenerateCommand.cs:line 76
--- End of stack trace from previous location where exception was thrown ---
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.Invoke(MethodInfo method, Object instance, Object[] arguments)
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context, CancellationToken cancellationToken)
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at EntityFrameworkCore.Generator.Program.Main(String[] args) in C:\projects\entityframeworkcore-generator\src\EntityFrameworkCore.Generator\Program.cs:line 50
I think I was missing some dependencies package. But, I am not sure what is it.
Thank you very much
I've found the solution, and decide to post it here because It may help other people in the future.
Actually, efg command will use SqlServer provider if we not mentioning any "provider" parameter. So, I've revised my command into:
efg generate -c "Host=localhost;Username=admin;Database=dbTest;Password=admin;Persist Security Info=True" -p PostgreSQL
While running swagger on VS2013 WebAPI project , I get the following error
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Object reference not set to an instance of an object.
</ExceptionMessage>
<ExceptionType>System.NullReferenceException</ExceptionType>
<StackTrace>
at Swashbuckle.Application.SwaggerDocsConfig.DefaultRootUrlResolver(HttpRequestMessage request) at Swashbuckle.Application.SwaggerDocsConfig.GetRootUrl(HttpRequestMessage swaggerRequest) at Swashbuckle.Application.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.HttpServer.<>n__FabricatedMethod5(HttpRequestMessage , CancellationToken ) at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext()
</StackTrace>
</Error>
Steps done
1.Install SwashBuckle Nuget package
2.Modify the Swagger.cs file to include the basic required code.
3.Run the WebApi.
4. Append /swagger in the API url.
After the 4th step is implemented, I get the above mentioned error.
Please help.
Install Nuget package Microsoft.AspNet.WebApi.WebHost version 5.2.3