Base solution for your next web application

Activities of "pkut"

Hello,

I'm trying to insert some database record and catch duplicate key exception. Actually it is not primary key but unique index defined for the table. The example of code looks like this:

public void DoSomething()
{
    ...
    var record=new MyRecord {....};
    try
    {
        repository.InsertAsync(record);
    }
    catch (DbUpdateException e) when ((e?.InnerException?.InnerException as System.Data.SqlClient.SqlException)?.Number == 2601){
        record=repository.FirstOrDefault(...some condition here...);
    }
    --Some more database code comes here and finally I'm saving another peace of data.
}

And if my code contains some more data changes later, it cannot be saved. It looks like faulty MyRecord instance still waiting in the DbContext and even I've catched the exception, it will try to save it again on the next SaveChanges attempt. How should I correctly manage this situation? Should I manually define two unit of work - one to insertion attempt and the secod for the rest of the code? Thank you in advance.

Best regards Pavel.

Question

Hello!

Couple of times we have faced very strange and annoying behaviour. Our project deployed on Azure as an App Service. And accidentally our customers complained that they cannot login. We found that after successful login browser hangs on attempt to receive responce from /AbpScripts/GetScripts call. It waits for 3.8 min and failed with 500 error. 3.8minute is an Azure magic number - this is a time that single request allowed to run before it will be kicked off by the system. Complete service restart solves the problem. But we have no idea how to prevent this in the future. log4net logs are turned on and contains nothing (maybe we badly configured it in release mode). Any ideas will be very appreaciated.

Best regards Pavel.

Hello,

I'm trying to run 4 unit tests that was automatically generated for empty project. When I'm trying to debug it I got "SQL server is not accessible" error inside DbContext constructor. Debugging it I can see that DbContext constructor receives connection that is instance of "Effort.ProviderEffortConnection" - seems to be ok. But anyway later I got the error above- it looks like something is trying to create real DBContext instead of Effort. When I put connection string to the App.config, I got "database not initialized" error or something like this. What should I do, maybe some little setting was missed? Thank you in advance.

Showing 1 to 3 of 3 entries