> Yes I am talking about sql statements that are concanentated in code.
> I am not sure what your talking about when you say parameterized
> queries, could you explain.
RUN, don't walk, to your favorite search engine and search on SQL Injection.
Get rid of your concatented sql statements NOW! In short, consider the following
SQL:
"Select * from Employee where EmployeeId = " & txtSearchString.text
This works fine as long as the user puts a valid value into the box. Now
what happens if they enter "1 or 1=1" in the txtsearchstring box? All employee
records will be returned. If we get meaner, we could enter "1 ; Drop Table
Employee". Hopefully you can figure out what will happen now. I've heard
that some security companies have come up with a fully functioning SQL Enterprise
Manager solely using SQL Injection attacks on a vulnerable web application.
As a better alternative, here is an example of a parameterized SQL statement:
Using cn = New SqlConnection(MyConnectionString)
dim cm as as SqlCommand = cn.CreateCommand
cm.CommandType = commandType.Text
cm.CommandText = "Select * from Customers where City = @City"
cm.Parameters.AddWithValue("@City", txtSearchString.text)
dim dr as DataReader = cm.ExecuteReader
From a code standpoint, parametrized SQL behaves much like stored procedures.
The difference is, you aren't defining the procedure on the server, but in
your code. SQL Server will still cache the execution plan on parameterized
queries as long as the parameter list does not change (the parameter values
can change without effecting the cache). Becasue we are parameterizing the
results, entering one of the invalid responses above will not have the same
undesired effects as the server does not see the invalid values as additional
commands to execute, but just values to compare against.
Jim Wooley
http://devauthority.com/blogs/jwooley/default.asp
kentk - 24 May 2006 21:34 GMT
Yea, I understand what you are talk about now, parameterized queries is what
I do now. I left concatenation behind in VB6.
But just to reiterate there is not much difference in performance between a
stored proc and a parameterized query? Would you know if there is a
performance difference running parameterized queries on SQL 7 vs 2000 fro
VB.NET?
Michel Posseth [MCP] - 26 May 2006 14:59 GMT
The performance debate is about the fact that every SQL statement to SQL
server is compiled ( a lot of people believe that this is the main
pefformance benefit of a SP ) however it isn`t as SQL compiles every SQL
statement that it receives
when would you use a SP (when you only consider performance ) ??
when you call a query a lot of times a SP would be faster
1. the execution plan`s that sql server makes
2. the amount of data overhead is lower
regards
Michel Posseth
> Yea, I understand what you are talk about now, parameterized queries is
> what
[quoted text clipped - 5 lines]
> performance difference running parameterized queries on SQL 7 vs 2000 fro
> VB.NET?
William (Bill) Vaughn - 31 May 2006 18:27 GMT
I posted a discussion of this on my blog.
http://betav.com/blog/billva/2006/05/are_sps_faster_than_adhoc_quer.html
hth

Signature
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Michel Posseth [MCP]" <MSDN@posseth.com> wrote in message news:OGfixxMgGHA.4276@TK2MSFTNGP03.phx.gbl...
>
> The performance debate is about the fact that every SQL statement to SQL
[quoted text clipped - 22 lines]
>> performance difference running parameterized queries on SQL 7 vs 2000 fro
>> VB.NET?
Jim Wooley - 31 May 2006 21:14 GMT
Bill, it appears you omitted the underscores when copying the url. I believe
this is what you were refering to:
http://betav.com/blog/billva/2006/05/are_sps_faster_than_adhoc_quer.html
Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
> I posted a discussion of this on my blog.
> http://betav.com/blog/billva/2006/05/are sps faster than adhoc
[quoted text clipped - 40 lines]
>
>>> VB.NET?
William (Bill) Vaughn - 31 May 2006 22:47 GMT
Hummm. It worked for me from the original posting--the underscores were
there.

Signature
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
> Bill, it appears you omitted the underscores when copying the url. I
> believe this is what you were refering to:
[quoted text clipped - 48 lines]
>>
>>>> VB.NET?