如何使用sql server避免在Windows应用程序中出现问题 [英] How to avoid jam in windows application using sql server

查看:61
本文介绍了如何使用sql server避免在Windows应用程序中出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好



我在c#.net中创建了一个商业应用程序,我在服务器中使用



多个用户。虽然所有用户一次创建一次发票,但是花费了更多的时间,有时应用程序没有响应条件。



注意:当一个用户在发票上创建时没有自动增加



使用增加的发票编号保存另一个用户。 />


你能不能建议我如何解决这个问题。



创建发票的代码



Hi

I have created one business application in c#.net and I am using in server containing

multiple users. While creating the invoices by all the users once at a time it has been

taken more time and sometimes application getting not responding condition.

Note: When one user created on invoice no then automatically that will be incremented

saving the other user with incremented invoice no.

would you please suggest me how to overcome this problem.

My Code for creating Invoice

{


               string strTran = "";
               strTran = cfs.getTRNumber("INV", cpnyid);
               ddl_Inv.Text = strTran;

               if (txt_Cus_Name.Text == "")
               {
                   MessageBox.Show("Please select Customer.", Properties.Settings.Default.ProductName.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                   txt_Cus_Name.Focus();
                   return;
               }
               else if (dataGridViewEx1.Rows.Count < 1)
               {
                   MessageBox.Show("Please add Products to save your order.", Properties.Settings.Default.ProductName.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                   return;
               }

               else
               {

                   //20150707dav
                   if (ddl_Inv.Text.Length < 9)
                   {
                   
                   sqlstr = "select INV_NO from " + tablename + " where INV_NO='" + ddl_Inv.Text + "' and Deleted=0 ";
                       if (cfs.checktrno(sqlstr) == false)
                   {

                       strTran = cfs.getTRNumber("INV", cpnyid);
                       //MessageBox.Show("Invoice: " + ddl_Inv.Text + " already existed in database." +
                       //    "\r\n[Updating Invoice With New " + strTran + " save again]", Properties.Settings.Default.ProductName.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                       ddl_Inv.Text = strTran;
                       if (Basic.Default.ismulno == false)
                       {
                           cmd.CommandText = "update rstockno set RS_INV_NO='" + Properties.Settings.Default.trno.ToString() + "' where ID='" + cpnyid + "'";
                           cmd.ExecuteNonQuery();
                           cn.Close();
                       }
                       if (CheckForPrice(dataGridViewEx1).Count > 0)
                       {
                           string price = "";
                           foreach (string str in CheckForPrice(dataGridViewEx1))
                           {
                               price += str + ",";
                           }
                           DialogResult result = MessageBox.Show("Price can not be '0.00'.Do you want to proceed? This will effect the costing", "Warning",
                                                 MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                           if (result == DialogResult.No)
                           {
                               return;
                           }
                           else
                           {
                               save();
                               txt_Quo_ExtRema.Enabled = true;
                               lsPrice();
                               lsPrice2();
                           }
                       }
                       //ddl_Inv.Text = "";
                   }
                   else
                   {
                       save();
                       lsPrice();
                       lsPrice2();
                       //txt_Quo_ExtRema.Enabled = true;
                   }
               }
           }
           catch { if(!dr.IsClosed==true)dr.Close(); }
           Properties.Settings.Default.RowCount = 0;

       }





在保存方法中,我写了发票的插入查询



In save method I have written insert query of invoice

推荐答案

从描述中我怀疑你可能有一两个主要问题。



第一个可能更容易,缺乏足够的索引。数据库结构应该由一个人验证

- 知道如何优化数据库

- 已经(或提供)了解应用程序行为的充分知识估计表的常见用例。



第二个,很可能是你有一个锁定问题。例如,当创建新发票时,听起来您从表中获得了一个新数字。现在,如果此表在发票插入期间被锁定,则最终会导致此表成为瓶颈。



如果是这种情况,要解决这个问题,你需要改变程序的事务行为;使锁定激活的时间显着降低,或更改创建新数字的方式。此问题可能需要对应用程序进行大量更改。
From the description I suspect that you may have one or two main problems.

The first one is perhaps easier, lack of sufficient indexes. The database structure should be verified by a person who
- has the knowledge how a database is optimized
- has (or is provided) sufficient knowledge of the application behaciour in order to estimate common use cases for the tables.

The second one, which is quite probable, is that you have a locking problem. For example when the new invoice is created it sounds you get a new number form a table. Now if this table is locked for the duration of the invoice insertion you end up in a situation where this table becomes a bottleneck.

If this is the case, to overcome the problem you need to change the transaction behaviour of the program; Make the time of the lock being active significantly lower, or change the way you create a new number. This problem may require extensive changes in the application.


这篇关于如何使用sql server避免在Windows应用程序中出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆