简体   繁体   English

后端使用SQL Server 2008的C#.Net应用程序上的TCP错误

[英]TCP error on a C#.Net application with SQL Server 2008 on the backend

I have made an application using C#, .Net and SQL Server as a database tool. 我已经使用C#、. Net和SQL Server作为数据库工具制作了一个应用程序。

Today I run it on a multi-user environment. 今天,我在多用户环境中运行它。 I hosted SQL Server on server and install the application on client computers. 我将SQL Server托管在服务器上,并在客户端计算机上安装了该应用程序。 Initially it is working fine but after some time I got an error message. 最初它工作正常,但一段时间后出现错误消息。 The screen shot of error is given below. 错误的屏幕截图如下。

在此处输入图片说明

I used this code to create the connection string - 我使用此代码创建了连接字符串-

  class SqlConnDAC
    {
         public static SqlConnection CreateConn()
          {
           SqlConnection con = new SqlConnection(@"Data Source=XXX.XXX.X.XXX\SQLEXPRESS;Initial    Catalog=TrulyDB;User ID=sa;Password=XXXXXXXX");
           return con;
           }
     }

And I use the following code to insert data into OCF table- 我使用以下代码将数据插入到OCF表中-

        public string OCF_EntryDB_Commerce(OCF_BO formDb)
    {
        try
        {
            string intOCF=formDb.OCF_Cont_No;

            SqlConnection con = SqlConnDAC.CreateConn();
            SqlDataAdapter sda = new SqlDataAdapter("select * from OCF_Commerce", con);
            DataSet ds = new DataSet();
            sda.Fill(ds, "OCF_Commerce");
            DataTable dt = ds.Tables["OCF_Commerce"];
            DataRow dr = dt.NewRow();
            dr[0] = formDb.OCF_Cont_No;
            dr[1] = formDb.Customer_Name;
            dr[2] = formDb.Order_Cont_Type;
            dr[3] = formDb.Book_No;
            dr[4] = formDb.Area_To_Be_Served;
            dr[5] = Convert.ToInt32(formDb.No_of_Floor);
            dr[6] = formDb.Type_Of_Premisses;
            dr[7] = formDb.Phone_Number;
            dr[8] = formDb.Email_ID;
            dr[9] = formDb.Adress;
            dr[10] = formDb.Adress_To_be_serverd;
            dr[11] = Convert.ToInt32(formDb.Cont_Value);
            dr[12] = Convert.ToInt32(formDb.Cont_Tax);
            dr[13] = Convert.ToInt32(formDb.Total);
            dr[14] = formDb.Cont_Date;
            dr[15] = formDb.Cont_Month;
            dr[16] = formDb.Cont_Year;
            dr[17] = formDb.Service_Start_Date;
            dr[18] = formDb.Service_Start_Month;
            dr[19] = formDb.Service_Start_Year;
            dr[20] = formDb.Cont_Period_From;
            dr[21] = formDb.Cont_Period_From_MM;
            dr[22] = formDb.Cont_Period_From_YY;
            dr[23] = formDb.Cont_Period_To;
            dr[24] = formDb.Cont_Period_To_MM;
            dr[25] = formDb.Cont_Period_To_YY;
            dr[26] = formDb.TermsOfPayments;
            if (formDb.TypeOfSite == "SingleSite")
            {
               intOCF = formDb.OCF_Cont_No;
            }
            else if (formDb.TypeOfSite == "MultipleSite")
            {
                intOCF = GenerateInt_OCF(formDb.OCF_Cont_No);

            }

            dr[27] = intOCF;
            dr[28] = formDb.OperatingBranch;

            OCF_Int_ID.internalOCF = intOCF;
              dt.Rows.Add(dr);
            SqlCommandBuilder sbil = new SqlCommandBuilder(sda);
            sda.Update(dt);

            return ("\nDone - and internal OCF number for "+formDb.Adress_To_be_serverd+" ="+intOCF+" \n");
       }
  }

My first thought was that you have a network issue. 我的第一个想法是您遇到了网络问题。 But there are other reasons such as too many SQL requests etc. Take a look at Microsoft technet 但是还有其他原因,例如SQL请求过多等。请查看Microsoft technet

Just as some advice on the SQL to save you some headaches down the line: You're using a select * and then reading the fields by the order they come back in. If you plan any upgrades to the product look at getting the values back using the field names, that way when you add or remove or change fields your code won't break. 就像有关SQL的一些建议可以帮助您省去一番烦恼一样:您正在使用select *,然后按照它们返回的顺序来读取字段。如果您计划对产品进行任何升级,请查看将值取回使用字段名称,这样,当您添加或删除或更改字段时,代码不会中断。 Also there is the issue of the select * having to hit the master database to get the list of fields, it's a minor performance hit, but if master gets busy from a lot of them it can become a bottle neck or worse still lock up. 还有一个问题,那就是select *必须命中master数据库以获取字段列表,这对性能影响不大,但是如果master忙于其中的很多事情,它可能会成为瓶颈,或者更糟糕的是仍然被锁定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM