|user.Id==0) {logger.Error($"Incorrect result{user.Id}")} can see any result in Log file. This problem has troubled me for a ...

问题描述 投票:0回答:1
I also think it is possible a concurrency issue. so i code a simple select use ado.net , the problem is still
var user =  Db.Single<User>(x => x.Id==1); 
   if(user.Id!=1||user.Id==0)
{logger.Error($"Incorrect result{user.Id}")}

servicestack ormlite
1个回答
1
投票

@@SPID return 0 or throw an exception Input string was not in a correct format. Just like select @@spid int but return varchar

  string sql = $" select * from where Id=1 ";
                                using (SqlConnection connection = new SqlConnection(dbConnectionString))
                                {
                                    DataTable dt = new DataTable();
                                    connection.Open();
                                    SqlDataAdapter sda = new SqlDataAdapter(sql , connection);
                                    sda.Fill(dt);
                                    connection.Close();
                                    sda.Dispose();
                                    if (dt != null && dt.Rows.Count > 0)
                                    {
                                    var    user= dt.ToSingleModel<User>();
                                    }
                                } 

0
投票

Another interesting thing happened todayIn redis

then we found item's type is UserSession in Log file

 public T SingleById( int id)
        {
            var result = Db.SingleById<T>(id);
            if (result == null || result.Id != id)
            {
                var first = result.ToIndentedJson();
                result = Db.SingleById<T>(id);
                if (result == null || result.Id != id)
                {
                    result =Db.SingleById<T>(id);
                    if (result != null)
                    {
                        LogQueryError(first,result, 2);
                    }
                }
                else
                {
                    LogQueryError(first, result, 1);
                }
            }          
            return result;    
        }

 public static readonly Logger LoggerMustDeal = LogManager.GetLogger("MustDeal");
 public void LogQueryError(string first, IEntityBase entityBase, int level = 1)
        {
            StackTrace st = new StackTrace(true);
            var frames = st.GetFrames();
            foreach (var sf in frames)
            {
                if (System.Diagnostics.StackFrame.OFFSET_UNKNOWN == sf.GetILOffset()) break;
                var fileName = sf.GetFileName();
                if (sf.GetMethod() == null || (!fileName.IsNullOrEmpty() && !fileName.Contains("LastOne")))
                {
                    break;
                }
                var str =
                    $"{fileName} {sf.GetMethod().Name} {sf.GetFileLineNumber()} {sf.GetFileColumnNumber()}";
                LoggerMustDeal.Error($"sqlserver error {str}");
            }


            LoggerMustDeal.Error($"sqlserver error first data {first}");
            LoggerMustDeal.Error($"sqlserver error times {level}  {entityBase.ToIndentedJson()} {Db.ConnectionString}");
            var spId = Db.Single<int>("select @@SPID");
            LoggerMustDeal.Error($"spid:{spId}");
        }

A few days ago, through log analysis, the database was almost the same. The wrong result was queried, usually the result that another thread just queried and gotDoes it feel like a memory or network layer problem?What is your opinion on this? @mythz

2020-04-27 16:28:34.9112 ERROR sqlserver error first data {
  "Name": "",
  "StartTime": "0001-01-01T00:00:00",
  "EndTime": "0001-01-01T00:00:00",
  "ActivityType": 0,
  "ActivityRangeType": 0,
  "IsOpen": false,
  "ActivityFlag": null,
  "Timer": 0,
  "State": 2,
  "Id": 3,
  "Delstatus": false,
  "AddTime": "2020-02-04T18:36:03.883",
  "UpdateTime": "2020-04-27T10:04:13.713",
  "MallId": 1
}
2020-04-27 16:28:34.9112 ERROR sqlserver error times 1 {
  "Name": "test",
  "StartTime": "2020-04-18T00:00:00",
  "EndTime": "2020-04-19T00:00:00",
  "ActivityType": 1,
  "ActivityRangeType": 1,
  "IsOpen": true,
  "ActivityFlag": "test",
  "Timer": 0,
  "State": 2,
  "Id": 219,
  "Delstatus": false,
  "AddTime": "2020-04-13T17:38:48.83",
  "UpdateTime": "2020-04-13T17:38:48.83",
  "MallId": 15
} server=xxxx;uid=xxxx;pwd=xxxx;database=xxxx;max pool size=40000;Pooling=true;

0
投票

The problem seems to have been solved.

key                    value
Urn:sid               {"__type":"UserSession"}               
OrderPaySettle        {"__type":"ServiceInterface.SettleOrder"}

Thread A Redis.Get<UserSession>("Urn:sid")    at 2020-04-29 06:27:53.0000
Thread B Redis.Get<object>("OrderPaySettle")  at 2020-04-29 06:27:53.8009
var item = Redis.Get<object>("OrderPaySettle") 

In my code , There will be many such examples , one api service resolve any other service and every service will open a dbconnction , and dbconnction dispose on service dispose . so there may be many opened dbconnections at the same time.

I created the DAL layer ,dbconnction will dispose after exec

Since this change, there have been no problems for more than 20 consecutive daysBut I still don’t know where the problem is.May be many opened dbconnections at the same time will abnormal ?


0
投票

public object Post(RequestA request)
  {
    using var servceA=ResolveService<ServiceA>();
    using var servceB=ResolveService<ServiceB>();
    using var servceC=ResolveService<ServiceC>();
    .......
    using var servceN=ResolveService<ServiceN>();

    ...
    ...
  }    

var user = Db.Single

public T Single(SqlExpression<T> exp)
  {
    using var db = HostContext.AppHost.GetDbConnection(Request);
    var result = db.Single(exp);
    return result;
   }

(x => x.Id==1); if(user.Id!=1)

© www.soinside.com 2019 - 2024. All rights reserved.