question

BhanuPratapSingh-0368 avatar image
0 Votes"
BhanuPratapSingh-0368 asked ·

Unable to publish grandnode where mongodb is database

I have published my asp.netcore app which uses mongodb as database from visual studio, but while installing it, it is unable to create database or may be error while connecting database,

error is as given below:
A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "2", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 2, EndPoint : "Unspecified/grandnodemongo.mongo.cosmos.azure.com:10255" }", EndPoint: "Unspecified/grandnodemongo.mongo.cosmos.azure.com:10255", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server. ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream. at MongoDB.Driver.Core.Misc.StreamExtensionMethods.ReadBytesAsync(Stream stream, Byte[] buffer, Int32 offset, Int32 count, TimeSpan timeout, CancellationToken cancellationToken) at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBufferAsync() --- End of inner exception stack trace --- at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBufferAsync() at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBufferAsync(Int32 responseTo, CancellationToken cancellationToken) at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveMessageAsync(Int32 responseTo, IMessageEncoderSelector encoderSelector, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken) at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken) at MongoDB.Driver.Core.Connections.IsMasterHelper.GetResultAsync(IConnection connection, CommandWireProtocol`1 isMasterProtocol, CancellationToken cancellationToken) at MongoDB.Driver.Core.Connections.ConnectionInitializer.InitializeConnectionAsync(IConnection connection, CancellationToken cancellationToken) at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken) --- End of inner exception stack trace --- at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken) at MongoDB.Driver.Core.Servers.ServerMonitor.HeartbeatAsync(CancellationToken cancellationToken)", LastUpdateTimestamp: "2020-05-11T22:55:10.4489871Z" }] }.

azure-webappsazure-cosmos-db
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Are you relying on the connection string configuration in the web.config or have you explicitly set the Cosmos Database connection string information in the Application Settings connection strings section for your web application? Please see: Configure App Settings. The web.config can be used to connect when developing locally in Visual Studio (either for the Emulator or the Cosmos DB MongoDB API instance) but if you have published your app to Azure App Service, you will need to configure a connection string, and not reply on the web.config.


1 Vote 1 ·

1 Answer

Mike-Ubezzi-MSFT avatar image
0 Votes"
Mike-Ubezzi-MSFT answered ·

Wanted to provide information about publishing .NET web applications with the Azure Cosmos DB API for MongoDB. The tutorial demonstrates how to update the connection string in the project (see: update connection string). The following section details how to install the MongoDB driver (see: run the web app). The next step would be to publish the solution to Azure App Service, as the Quickstart has you build and run the solution locally in Visual Studio while connected to your Azure Cosmos DB API for MongoDB instance remotely.

Quickstart: Build a .NET web app using Azure Cosmos DB's API for MongoDB (link)

For information on how to publish a web application to Azure App Service, please see the following: Publish a Web app to Azure App Service using Visual Studio. The difference between a non Cosmos DB based web application and a Cosmos DB API for MongoDB based web application is the driver and connection string reference in the code base where a non Cosmos DB web app uses web.config and the connection string entry in the App Service settings.

Please make sure your solution has the correct driver installed and the code base includes the connection string. If you can run the solution locally in Visual Studio and connect to the remote instance of the Cosmos DB API for MongoDB then the solution should run in the App Service environment. The only item that would prevent connectivity would be firewall related (public endpoint versus selected network endpoint).


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.