0

I have read the other threads on this, and none of them have answers that resolve my current scenario, nor are they similar. My scenario is reproducible on each run of my application, though I can't seem to produce a smaller piece of code that creates this error.

I'm getting the following error:

An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy.

The inner exception says:

A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.)

I am not connecting to a SQL Azure database. The connection is to a remote database through VPN, hosted on premises. To give some more context, I'm importing data from an external system, and every time it gets up to a specific record, it always fails when I try to update the entity after creating it. I've tried setting debug logging on in EF and copying the statement it generates into SSMS and running it with the same credentials with no errors. The only differentiating factor between this record and the previous records are the audit fields (time created/modified) and the name, which has changed from 1USD - Holding 99 to 1USD - Holding 100. I actually tested out changing the order which the records get imported, and it always fails at 100 when editing in EF after creation, so there's probably some other underlying issue at hand here. The field itself in the database is handling strings with a higher length than this, including this same process with no errors.

This obviously doesn't seem to actually be a transient failure, nor does it seem to be a connection issue, so how do I find the exact reason why this doesn't work?

Edit: Adding some code below. Also, I've noticed that if I change the name to 1USD - Holding 99 - Test 2, it works without any error despite the name being longer. Automatic ChangeDetection is not enabled for performance reasons.

            security = new Security
            {
                Name = securityName,
                IsActive = true,
                CreatedAt = DateTime.Now,
                CreatedBy = ADMIN_USER,
                ModifiedAt = DateTime.Now,
                ModifiedBy = ADMIN_USER
            };

            _repository.Save(security); //Ctx.Set<T>().Add(security); Ctx.SaveChanges();

            //some attributes with a foreign key referencing this entity are saved, which is why we update audit fields below, but error occurs regardless if anything additional is saved

            security.ModifiedBy = ADMIN_USER;
            security.ModifiedAt = DateTime.Now;
            _repository.Save(security); //Ctx.Set<T>().Attach(security); Ctx.Entry(security).State = EntityState.Modified; Ctx.SaveChanges();

Edit 2: It definitely seems to be something else other than a connection issue since it's happening for anything ending in a 3 character combination, such as A10, B10, or 10A. 1, 2, or 4 characters seem to be fine. Still have no idea what the actual issue is, however.

Lunyx
  • 3,164
  • 6
  • 30
  • 46
  • Can you update your question and show us the code segment where the error is being thrown? – devlin carnate Aug 28 '20 at 21:21
  • @devlincarnate Added the relevant code as well as some additional tests I did. – Lunyx Aug 28 '20 at 21:29
  • Can you show where you get your db context in relation to the attempt to save? specifically, i'm wondering if the connection to your db context is actually there or whether it's closed? – devlin carnate Aug 28 '20 at 21:37
  • @devlincarnate We have IoC framework which injects the `Repository` into the class saving these records. The `Repository` resolves a new `DbContext` based on the connection string that is injected into `Repository`. – Lunyx Aug 28 '20 at 21:40
  • Might be worth verifying that _repository has a valid connection https://stackoverflow.com/questions/19211082/testing-an-entity-framework-database-connection – devlin carnate Aug 28 '20 at 21:42
  • @devlincarnate, the connection is definitely valid as it only fails on that specific name having `100` in it. The same connection is being used to create other records which do not exhibit this behavior. That's why I'm just very confused since the error it's reporting doesn't seem to match up. For the record, `101` and above don't work either. – Lunyx Aug 28 '20 at 21:44

0 Answers0