English 中文(简体)
利用ExecuteNon Query进行证券交易
原标题:Concurrency-Issue using ExecuteNonQuery

I m 书写简单的文字记录

private SqlConnection sqlcon;

// ...

try {
    sqlcon.Open();

    SqlCommand cmd = sqlcon.CreateCommand();
    cmd.CommandText = this.logString;

    cmd.ExecuteNonQuery();
} 
/* catch SqlException, InvalidOperationException, Exception */ 
/* finally sqlcon.Close() */

A. 同步 处理被定为不实,因此认为记录条目按执行顺序出现在表格中。 但情况并非如此,如果发射2个或2个以上正数少于5个。

因此,我的猜测是,ExecuteNon Query的行踪不一,而不同事件的交织在一起。 我已经尝试过与BeginExecuteNon Query和EndexecuteNon Query一道使用Asynchronous加工,但是它评估我的法典,并不真正地工作。

So my question is: Is there any way to ensure, that the nonQueries are being executed in exactly the order they were triggered?

edit: Maybe it s important, i m using a timestamp like so

cmd.Parameters.Add("timestamp", SqlDbType.DateTime ).Value = System.DateTime.Now;
最佳回答

如果您使用服务器SYSDATETIME插入时间段? 我想 ExecuteNon Query是同步的,但可能与你的时间相差。

http://download.microsoft.com/download/3/0/2/3027D574-C433-412A-A8B6-5E0A75D5B237/timer- Resolution.docx” rel=“nofollow”

问题回答

Asynchronous?

请<>开放/连接 每当你能够真正相信这一点时,就会有,有些则相当于<>>。 (请原谅我) BeginExecuteNon Query (这是在MARS之前采用的方法)。 实际上,每项请求都是同步的,但如果你在5个半位位位数上下,可以肯定SQ服务器会为这些要求服务(这里的银行会想到old<>m> > IDENTITY栏问题)。

TimeStamp

然后,解决办法应该是使用一个时间表栏,并根据该栏(按标准顺序排列)确定结果。 它是一个完美的解决办法(正如其他答复所指出的,它不会忘记利用正确的数据类型储存数据)。

如何获得实际时间? 可在用户方面(如您的榜样)使用<代码>Datetime.Now,,或使用<编码>SYSDATETIME(如@Petr Abdulin所示)。 如果你不需要高分辨率/高分辨率,它就是一个完美的解决办法。

PRECISION

这两项职能都依赖Windows系统的时间,其分辨率等于10米以上(当时,如果你真需要5毫微粒,你就应当避免)。

On MSDN you can read that DateTime.Now on Windows NT has a resolution of 10 ms, the SYSDATETIME calls GetSystemTimeAsFileTime, the FILETIME structure has a 100 ms precision but the timer itself isn t granted to achieve that result!!! In some conditions you may even get a 1 ms tick but it s not reliable at all. In the documentation about the StopWatch timer you can read:

The timer used by the Stopwatch class depends on the system hardware and operating system. IsHighResolution is true if the Stopwatch timer is based on a high-resolution performance counter. Otherwise, IsHighResolution is false, which indicates that the Stopwatch timer is based on the system timer.

它意味着什么? 从来没有批准过一个系统的时间来达到高分辨率(不会因为储存时间所使用的结构的精确性而混淆)。

It could be a problem or not, it depends for what you ll use your logs. If you have to log the list of file copied from one folder to another during a backup then you may not need such precision. If your logs may be used for legal stuffs (yes, I know they should not have any legal value) or to debug a subtle threading issue then you ll need it.

SOLUTIONS

如果需要高分辨率的时间(在视窗上,您可考虑任何细节;10个高分辨率的圆点)的话,你必须处理业绩表。 查阅,这是关于时间的重要文章。 当然,你不需要一切,而是提出问题。

可在网上查阅<代码>Datetime.Now和StopWatch。 (查询IsHigh Resolution property)。 http://stackoverflow.com/questions/1416139/how-to-get-timestamp-of-ay-precision-in-net-c> 关于使用<代码>StopWatch以提高<代码>Datetime.Now的精确度的这个良好职位。

<>strong>COMMON ERRORS

首先,没有将储存时间所用的数据类型精确与时间的分辨率混为一谈。 如果你在低分辨率的领域中储存这一价值,而使用高分辨率的田野却不把你的ars时间变成高分辨率,那么你的时间是多少准确的。

此外,你不应利用当地时间作为时间序列,在系统时间因节省日光而改变时,你会把日志混为一谈。 想:

               00:00   02:00   02:01   03:00   02:00
Log              #1      #2      #3              #4
System time                             -1

现在,如果你读到你的记录,你就会照此办理:1,2,4,3。 日期:UtcNow和 SYSUTCDATET 功能(优于的性能) 日期:UtcNow稍有改善。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...