This is often down to differences in the
SET
options between SSMS and ADO.NET, which causes SQL to select a different execution plan.
ARITHABORT
is a common one - it's usually on in SSMS, but off for ADO.NET connections.
You can see the current options by looking at
@@OPTIONS
and performing some bit tests:
http://www.mssqltips.com/sqlservertip/1415/determining-set-options-for-a-current-session-in-sql-server/[
^]
You can change most of the default options in the properties of the database -
ARITHABORT
is "Arithmetic Abort Enabled".
Quite a lot of other possibilities are covered
in this article[
^] by
Erland Sommarskog[
^].