In one of my project have a table with above structure named TDocuments
.
CID
column is the Company ID and the table gets 40,000 companies every morning from a Windows application client database by connecting to backend API service and sending a request to my ASP.NET / C# web application (running on the .NET framework) with EF 6 send 50-100 thousand rows.
My policy is to delete all previous client data from the server database every day (with a delete query).
await _context.Database.ExecuteSqlCommandAsync(delete query)
Then I insert all the data again because new data has arrived on the client side or data has been edited and deleted (bulk copy).
await bulkCopy.WriteToServerAsync(dataTable);
Now last _id is 633,538,597
From client we send data page by page than every page have 10,000 records.
These days sometimes we have the following error when deleting or inserting:
Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Database details:
- Recovery mode is full
- Database size above 50 GB
- Table count above 20
- SQL Server 2017
This web server started 7 years ago.
Even when running a query directly in the SQL Server Management Studio, we have a slow speed.
I need to provide a more optimal solution in coding or database
Thank you for guiding me.