Didn't yet have any specific idea.
Is the connection open all the time during a single request? I mean that there is no way that the connection could be closed or disposed by your code before the failing statement?
StateChange event for the connection
- every time the state changes, write to a log file (or similar) both
OriginalState from event arguments
InfoMessage event for the connection
- write every element from
Errors collection from message event argument. Also write
Disposed event for the connection
- when Disposed occurs, write info about this to the log file
- write to the log file every time you get data context from httpcontext
- write to the log file every time you call open method on the sql connection
- write to the log file every time you execute the statements (especially the failing one)
- write to the log file every time you call close method on the sql connection
This should give a good output which shows the order how things are happening and some extra info what is actually happening.
Another thing that I'm thinking of is that why this doesn't happen on your local SQL Server but happens if you try to use SQL Server on another server. This could be because:
- network problems (packets are occasionally not delivered)
- the server under heavy stress and cannot respond
What do you think, could the reason be in those?