Same code running slower second time
-
Hello I am using Sql Server 2000 Developer Edition, Now I know there are limitations too how many connections you have BUT This piece of code below executes a whole lot slower the second time you run it.
switch(cbSearch.SelectedItem.ToString()) { case "Lastname": cmd = new SqlCommand("SPSearchRmiInfoLastname", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Lastname", txtSearch.Text); break; case "Firstname": cmd = new SqlCommand("SPSearchRmiInfoFirstname", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Firstname", txtSearch.Text); break; } conn.Open(); Search.Clear(); SqlDataReader drd = cmd.ExecuteReader(); while(drd.Read()) { Search.Rows.Add(new object\[\] {drd\[0\], drd\[1\], drd\[2\], drd\[3\]}); sbp.Text = Search.Rows.Count+" records found."; } dg.DataSource = Search; drd.Close(); conn.Close();
The results are staggering. First time: 1783 Milliseconds Second time: 150326 Milliseconds HOLY SHAZBOT!! Now that's a difference right there, Any ideas on why this is happening and how I can change it Thanks, Obe ------------------ I'm naked under my clothes...
-
Hello I am using Sql Server 2000 Developer Edition, Now I know there are limitations too how many connections you have BUT This piece of code below executes a whole lot slower the second time you run it.
switch(cbSearch.SelectedItem.ToString()) { case "Lastname": cmd = new SqlCommand("SPSearchRmiInfoLastname", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Lastname", txtSearch.Text); break; case "Firstname": cmd = new SqlCommand("SPSearchRmiInfoFirstname", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Firstname", txtSearch.Text); break; } conn.Open(); Search.Clear(); SqlDataReader drd = cmd.ExecuteReader(); while(drd.Read()) { Search.Rows.Add(new object\[\] {drd\[0\], drd\[1\], drd\[2\], drd\[3\]}); sbp.Text = Search.Rows.Count+" records found."; } dg.DataSource = Search; drd.Close(); conn.Close();
The results are staggering. First time: 1783 Milliseconds Second time: 150326 Milliseconds HOLY SHAZBOT!! Now that's a difference right there, Any ideas on why this is happening and how I can change it Thanks, Obe ------------------ I'm naked under my clothes...
Maybe you should change your store procedure, since you didn't post your SP, we don't know what kind of process happend there. "Courage choose who will follow, Fate choose who will lead" - Lord Gunner, Septerra Core "Press any key to continue, where's the ANY key ?" - Homer Simpsons Drinking gives me amazing powers of insight. I can solve all the worlds problems when drunk, but can never remember the solutions in the morning. - Michael P Butler to Paul Watson on 12/08/03
-
Maybe you should change your store procedure, since you didn't post your SP, we don't know what kind of process happend there. "Courage choose who will follow, Fate choose who will lead" - Lord Gunner, Septerra Core "Press any key to continue, where's the ANY key ?" - Homer Simpsons Drinking gives me amazing powers of insight. I can solve all the worlds problems when drunk, but can never remember the solutions in the morning. - Michael P Butler to Paul Watson on 12/08/03
-
This is my stored proc
CREATE PROCEDURE dbo.SPSearchRmiInfoLastname
(
@Lastname varchar(50)
)
AS
select * from RmiInfo where Lastname like @Lastname+'%' order by LastnameGO
------------------ I'm naked under my clothes...
WOW I figured it out I just put
dg.DataSource = null;
before it exeutes and it fixed it. somehow when you put a datatable into a datagrid whenever you add back to the datatable it is SLOW. hope this helps some people who come across this as well =) ------------------ I'm naked under my clothes...