强制保存/提交MSSQL数据

时间:2019-01-15 15:46:38

标签: c# sql-server

我有2个链接在同一数据库中的表。一个包含详细信息,另一个包含概述。

public SqlConnection conn;

    public bool Open()
    {
        if (conn != null && conn.State == System.Data.ConnectionState.Open)
        {
            return true;
        }

        conn = new SqlConnection(connectionString);

        try
        {
            conn.Open();
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }


  public bool InsertFilledAndUpdateOrder(long orderID, string newStatus int execSignedAmount)
    {
        try
        {

            if (!InsertFilled(orderID, "Filled",  execSignedAmount))
                return false;
        }
        catch (Exception)
        {
            return false;
        }

           //At this point I can see inserted record in MSSM

        try
        {
           //BUT this next query does NOT see it - until I step back in debugger and excute this line again!
            if (!UpdateOrderFromFilled(orderID))
                return false;

            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }

InsertFilled()和UpdateOrderFromFilled()是复杂的参数化查询,为简单起见,我没有显示。

上面的代码运行良好,直到我将其更改为在后台线程上-因此,这是某种线程问题。

ExecuteNonQuery的文档说,它阻塞直到插入/更新完成。但是,在这种情况下,尽管更改已在数据库中进行,但我的下一个查询没有看到它们!

0 个答案:

没有答案