I have a table-valued function that produces a simple report from my database. When I use this function from management studio it takes around 2 seconds to run, hits 253 logical reads and is granted a small amount of memory. When I run exactly the same query via a web service it never completes, hits hundreds of thousands of logical reads and is granted an enormous amount of memory.
Why would the query from the web service not run the same way as running it interactively?