I have a problem with executescalar being real slow on a table with over 200.000 records.
The method i use checks if an varchar exists in the table and returns a count to see if anything can be found:
public static bool AlreadyQueued(string url)
{
using (SqlConnection connection = new SqlConnection(_connectionString))
{
SqlCommand cmd = new SqlCommand("SELECT Count(queueID) from PriorityQueue where absolute_url = @url")
{
Connection = connection,
CommandType = CommandType.Text
};
cmd.Parameters.AddWithValue("@url", url);
connection.Open();
var count = (int)cmd.ExecuteScalar();
return count > 0;
}
}
My table is build like this:
CREATE TABLE PriorityQueue
(
queueID int IDENTITY(1,1) PRIMARY KEY,
absolute_url varchar (900),
depth int,
priorty int
);
Is there someway to make my C# method faster, or do I need to change something in my table?