Using Microsoft.Azure.Cosmos Fetch Data Form Azure Cosmos Db.
Facing Error on Live Site After 4k request**
Error:**
An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.
Generic Call:
public class CosmosConfigurationRepository : IDisposable
{
/// <summary>
/// The database identifier
/// </summary>
private readonly string databaseId = string.Empty;
/// <summary>
/// The collection identifier
/// </summary>
private readonly string collectionId = string.Empty;
/// <summary>
/// The client
/// </summary>
private readonly CosmosClient client;
/// <summary>
/// The container
/// </summary>
private readonly Container container;
/// <summary>
/// Initializes a new instance of the <see cref="CosmosConfigurationRepository"/> class.
/// </summary>
/// <param name="context">The context.</param>
public CosmosConfigurationRepository(SnmpCosmosContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
this.databaseId = context.DatabaseId;
this.collectionId = context.CollectionId;
string endpoint = context.Endpoint;
string authKey = context.AuthKey;
this.client = new CosmosClient(endpoint, authKey);
this.container = this.client.GetContainer(this.databaseId, this.collectionId);
}
/// Finalizes an instance of the <see cref="CosmosConfigurationRepository"/> class
/// </summary>
~CosmosConfigurationRepository()
{
this.Dispose(false);
}
/// <summary>
/// The ExecuteQuery.
/// </summary>
/// <returns>container <see cref="Container"/>Object type.</returns>
public Container GetCosmosContainer()
{
return this.container;
}
/// <summary>
/// The ExecuteQuery.
/// </summary>
/// <typeparam name="T">Object type.</typeparam>
/// <param name="query">The query<see cref="QueryDefinition"/>.</param>
/// <returns>The <see cref="FeedIterator{T}"/>Object type.</returns>
public FeedIterator<T> ExecuteQuery<T>(QueryDefinition query)
{
return this.container.GetItemQueryIterator<T>(query, requestOptions: new QueryRequestOptions() { MaxItemCount = -1 });
}
}
public async Task<List<PreDeliveryInspection>> GetPreDeliveryInspectionGridDataAsync(string fistName, string lastName)
{
List<PreDeliveryInspection> pdiDetails = new List<PreDeliveryInspection>();
QueryDefinition query =
new QueryDefinition(
"SELECT c.branchData FROM c Where c.lastName=lastName and c.lastName=@serial")
.WithParameter("@fistName", fistName).WithParameter("@serial", serial) ;
this.cosmosdbcredentials.CollectionId = this.containerConfig.BranchSystemData;
this.cosmosdb = new CosmosConfigurationRepository(this.cosmosdbcredentials);
FeedIterator<PreDeliveryInspection> data
= this.cosmosdb.ExecuteQuery<PreDeliveryInspection>(query);
while (data.HasMoreResults)
{
var response = await data.ReadNextAsync().ConfigureAwait(false);
pdiDetails.AddRange(response);
}
return pdiDetails;
}