Re: SqlConnection vs IDbConnection
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 13 Apr 2007 14:49:48 -0400
JoeW,
Yep, that looks fine to me.
Just remember that you have to keep the connection open as long as you
want to use the prepared statement.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"JoeW" <teh.sn1tch@xxxxxxxxx> wrote in message
news:1176489766.029398.229220@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Apr 13, 2:24 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
JoeW,
No, he isn't correct. IDbConnection, IDbCommand, and the like are
just
interfaces to abstract functionality on the provider-specific
implementations (like SqlConnection, SqlDataReader, SqlCommand, etc,
etc).
It doesn't imply anything.
If your command points to a stored procedure, then it is already
compiled. If you have a command that is a string that you are just
passing,
and need it prepared by the underlying provider, you would call the
Prepare
method on the IDbCommand implementation (this method is exposed
publically
on the implementation as well, most likely). That will prepare the query
for you with the underlying provider.
Note, if your command is a stored procedure, you don't want to call
Prepare. The execution plan for the stored proc has already been
generated.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"JoeW" <teh.sn1...@xxxxxxxxx> wrote in message
news:1176487111.667041.30200@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I normally use SqlConnection, SqlDataReader, SqlCommand for most of my
queries but recently a friend of mine who is a long time java
programmer suggested I use the IDbConnection, IDbCommand interfaces
because the queries where compiled instead of just executed like on
the open SqlConnection. Is he correct and if so does it really make a
difference as far as performance/security, etc?
Thanks for any suggestions- Hide quoted text -
- Show quoted text -
Ahh, I see. So this code would be fine?
string selectQuery = "SELECT time FROM " + TABLE_PREFIX + "referrers
WHERE url = @url AND ip = @ip";
_sqlCommand = new SqlCommand(selectQuery, _sqlConnector);
_sqlCommand.Parameters.AddWithValue("@url", pUrl);
_sqlCommand.Parameters.AddWithValue("@ip", pIp);
_sqlCommand.Prepare();
.
- Follow-Ups:
- Re: SqlConnection vs IDbConnection
- From: JoeW
- Re: SqlConnection vs IDbConnection
- From: JoeW
- Re: SqlConnection vs IDbConnection
- References:
- SqlConnection vs IDbConnection
- From: JoeW
- Re: SqlConnection vs IDbConnection
- From: Nicholas Paldino [.NET/C# MVP]
- Re: SqlConnection vs IDbConnection
- From: JoeW
- SqlConnection vs IDbConnection
- Prev by Date: Re: SqlConnection vs IDbConnection
- Next by Date: Interop with ASIO driver COM object
- Previous by thread: Re: SqlConnection vs IDbConnection
- Next by thread: Re: SqlConnection vs IDbConnection
- Index(es):
Relevant Pages
|