When you run a sql query in VB6, you should get similar performance as when you are running in through SQL Server Management Studio. It may be a little slower, but probably nothing noticeable.
Since the problem occurs infrequently, I would guess that you may be running in to a blocking situation. With SQL Server, blocking occurs when one query is modifying the data in a table and another query tries to read or modify the same data. In fact, it doesn't even need to be the same data because SQL Server will lock "pages" at a time. Each page is roughly 8kb of data and could contain 1 row or thousands depending on your table.
Generally speaking, I think the best method to prevent blocking is to make each query as fast as possible. If a query needs to update data, it will lock that data, make the changes and then unlock it. If the process takes 10 minutes, and query run by another process within that 10 minutes will be blocked. If the update process takes 2 milliseconds, then another query would need to be run within that 2 milliseconds.
So, the trick is to determine the query that is taking a long time to execute. The query you mentioned runs in 50 milliseconds, which is pretty fast already. That's not to say it couldn't be faster, but the real problem is the query that is blocking yours.
One way to determine the query that is blocking yours is to run a query like this:
sp_who2
This query should be run directly within a SQL Server management studio query window. It will return a result set with all of the active queries. An query with a SPID less than 50 can be ignored because those are built-in processes. You will see a column labeled BlkBy. This will be the SPID that is blocking your query. Once you identify the SPID that is blocking your query, you can run the following query.
DBCC INPUTBUFFER(The SPID here)
This will show you the exact query that is blocking yours. At this point, you can take a look at it and determine if there is a way to make it faster. One way to make updates faster (and less likely to block other queries), is to perform the update in batches. For example, suppose the offending query is updating all the data in a table (and that table has 900k rows). SQL Server will likely lock the whole table, perform the updates, and then unlock it. If you do the updates in batches it will only lock the data it needs to, perform the update, and then unlock the data.
Please understand that there is a lot of conjecture within my response. To know for sure, I would need to see the definition of the stored procedure, and also know for sure if the problem is with blocking.
-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom