I need some clarification on the behavior of SqlClient.SqlCommand.ExecuteScalar()
.
Are there are differences in behavior when polling a database using SqlCommand.ExecuteScalar()
, when the underlying SqlConnection
is in an open transaction state vs. just doing a one-off poll (no transaction out outside a transaction)?
More specifically:
-
If I were to
SqlCommand.ExecuteNonQuery()
some data into table, say,[Address]
, within an open transaction that has not yet been committed, would aSqlCommand.ExecuteScalar()
run just after that and inside the same transaction be able to see new data in[Address]
before transaction is committed? -
Would a
SqlCommand.ExecuteScalar()
run outside the transaction (also pre-commit) see that data? (I think the answer to this one is no, right?)