1

I have made an application using C#, .Net and SQL Server as a database tool.

Today I run it on a multi-user environment. I hosted SQL Server on server and install the application on client computers. Initially it is working fine but after some time I got an error message. The screen shot of error is given below.

enter image description here

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-

        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");
       }
  }
Chandan Kumar
  • 4,570
  • 4
  • 42
  • 62
Paul S
  • 81
  • 2
  • 13
  • 1
    What about you attach a debugger and give us the error message in text form, not in a screenshot? – TomTom Dec 11 '14 at 09:10
  • System.Data.SqlClient.SqlException (0x80131904): A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) ---> System.ComponentModel.Win32Exception (0x80004005): The specified network name is no longer available @KUMARCH – Paul S Dec 11 '14 at 09:25
  • follow this http://stackoverflow.com/questions/2266050/how-to-catch-properly-an-sqlexception-a-transport-level-error-has-occurred and this http://blogs.msdn.com/b/spike/archive/2009/04/16/a-transport-level-error-has-occurred-when-sending-the-request-to-the-server-provider-tcp-provider-error-0-an-existing-connection-was-forcibly-closed-by-the-remote-host.aspx – Chandan Kumar Dec 11 '14 at 09:28

1 Answers1

1

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

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. 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.

HSG
  • 334
  • 2
  • 8