-1

I have a Stored Procedure which when run on SQLServer takes 1 second to run, yet in my VB.Net code it takes nearly 20 seconds. It takes a long time on the line:

Adapter.Fill(ds,"TimeTable")

Am I doing something wrong for it to take so long?

My code snippet is below:

    SQLConn = New SqlConnection(SQLDConnString)
    cmd = New SqlCommand("SPNAME", SQLConn)
    cmd.CommandType = CommandType.StoredProcedure
    SQLConn.Open()
    cmd.Parameters.AddWithValue("@p1", p1)
    cmd.Parameters.AddWithValue("@p2", p2)
    cmd.Parameters.AddWithValue("@p3", p3)
    cmd.Parameters.AddWithValue("@p4", p4)
    adapter.SelectCommand = cmd
    adapter.Fill(ds, "TimeTable")
    DataGridView1.DataSource = ds.Tables("TimeTable")
    SQLConn.Close()
user1295053
  • 303
  • 1
  • 7
  • 17

2 Answers2

0

If your datagridview property for column and row height/width is set to auto, it can take a lot of time to finish the procedure. I had this happen once, where a stored procedure took an abnormally large amount of time and it ended up being that property that was causing it to stall.

Joel Priddy
  • 481
  • 3
  • 13
0

I seemed to find a fix to this by declaring local variables in my SP and then assigning my Parameters to these variables.

Something to do with parameter sniffing.

user1295053
  • 303
  • 1
  • 7
  • 17