• Begin by eliminating the obvious differences - your parameters are different datatypes between the two environments. The datatype of your parameters should match the datatype of the table columns wherever possible to avoid implicit conversions, which can make index seeks impossible.

    I'd try first changing the datatypes of your parameters in the SSMS script so that they match the datatype in the VS script, and comparing run times.

    Next, I'd modify the parameters so they match the datatype of the column they are compared to.

    Next, I'd put the SQL into a stored procedure. There are numerous good reasons for this including maintainability and plan reuse. Can you think of any good reasons not to do it?

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden