-4

Why does this run in about 7 seconds for a the first few times I run it and then get increasingly slower after that?

        using (SqlConnection con = new SqlConnection(connectionStr))
        {
            con.Open();
            using (SqlCommand sql = new SqlCommand("selectcombos"))
            {
                var returnParameter = sql.Parameters.Add("@val", SqlDbType.Int);
                returnParameter.Direction = ParameterDirection.ReturnValue;
                sql.Parameters.AddWithValue("@Id", ID);

                var timer = new Stopwatch();
                timer.Start();

                sql.CommandType = CommandType.StoredProcedure;
                sql.Connection = con;
                for (int i = 0; i < 50000; i++)
                {
                    sql.ExecuteScalar();
                    var res = returnParameter.Value;
                }
                timer.Stop();
                TimeSpan timeTaken = timer.Elapsed;
                string time = "Time taken: " + timeTaken.ToString(@"m\:ss\.fff");
                MessageBox.Show(time);
            }
        }

It is a large database table with about 100 million rows.

Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
davy
  • 4,474
  • 10
  • 48
  • 71
  • 4
    You **just posted this** not even five minutes ago - please do **NOT** re-post the same question over and over again! – marc_s Aug 06 '23 at 13:09

0 Answers0