B
Bob
I'm used to having my own code build the SQL that's passed to the SqlCommand
object, which is almost always in the format "EXEC
<databasename>.dbo.[<spname>] @<param1> = <something>, @param2 =
<something>, etc.". This is an habit from the days before I moved to DotNet,
which I am now reexamining. Maybe I should invoke stored procedures with the
built-in way (below)?
cmd = New SqlCommand
cmd.Connection = CurrentConnection
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = SomeStoredProcedureName
cmd.Parameters.Add("@param1", Param1Value)
cmd.Parameters.Add("@param2", Param2Value)
....
I have two questions regarding this:
1. My stored procedure names reside in different databases. I don't want to
have to check to see if I need to change the current connection's database
every time I invoke one. Only, when I put a fully qualified stored procedure
name into the CommandText property, it fails to parse anything with a dot in
it. Is the SqlCommand class just not designed to handle fully qualified
stored procedure names?
2. I always want to be able to see any SQL that's about to go to the server
if I need to. Where is the property in SqlCommand that will tell me what
it's about to send? Do I have to guess?
TIA,
Bob
object, which is almost always in the format "EXEC
<databasename>.dbo.[<spname>] @<param1> = <something>, @param2 =
<something>, etc.". This is an habit from the days before I moved to DotNet,
which I am now reexamining. Maybe I should invoke stored procedures with the
built-in way (below)?
cmd = New SqlCommand
cmd.Connection = CurrentConnection
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = SomeStoredProcedureName
cmd.Parameters.Add("@param1", Param1Value)
cmd.Parameters.Add("@param2", Param2Value)
....
I have two questions regarding this:
1. My stored procedure names reside in different databases. I don't want to
have to check to see if I need to change the current connection's database
every time I invoke one. Only, when I put a fully qualified stored procedure
name into the CommandText property, it fails to parse anything with a dot in
it. Is the SqlCommand class just not designed to handle fully qualified
stored procedure names?
2. I always want to be able to see any SQL that's about to go to the server
if I need to. Where is the property in SqlCommand that will tell me what
it's about to send? Do I have to guess?
TIA,
Bob