Base solution for your next web application

Activities of "pkut"

Hi,

Yes, we querying database first, but sometimes it's not enough and insert attempt fail on database constraint. So creating inner unit of work seems to be a solution, but - as far as I remember, documentation says that inner UOW uses the same connection and other DB related stuff as outer UOW. Looks like my understanding is a bit wrong here, please explain the details of how inner UOW works and how can I be sure that we have new DbContext.

Best regards Pavel

Hi.

We did exactly as you said, injected IUnitOfWorkManager and manually started UnitOfWork. But the problem is not directly with UOW, the problem actually will be the same if you will manually work with DbContext. When you need to add new record you do:

var myNewRecord=new MyRecord {  ....fill some data....}
context.MyRecordsTable.Add(myNewRecord);
try{
    context.SaveChanges();
}
catch (...database exception to handle failure....)
{
    //Catching unique constraint failure
}

When you fail on saving changes the myNewRecord will still be in the context and if you need to add another items to the database, you have to remove it someway - recreate DbContext or detach myNewRecord from context.

Now in AspNetBoilerplate actual DbContext is hidden, so how should I resolve the same situation ?

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.

Answer

Unfortunately I've Azure logs that when checking the problem. So for now I've turned on all logging that possible and waiting for the next case. Thank you for help.

Best regards Pavel.

Answer

Hi,

We have no external cache like Redis. As far as I understand nothing was customized to change scripts generation process or change user permissions processing..

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,

Sorry for bothering you, but we solved the problem. Actually we have changed database initializer when trying to deploy to Azure and this was very critical for unit tests. Setting up default initializer in the unit test project solves the problem. Thank you very much for so interesting framework.

Best regards

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 8 of 8 entries