SQL Server - Transact SQL / SQL with Parameters Newbie Question

Asked By Toni
18-Nov-09 05:09 PM
I run a website written in ASP (VBScript). I have been trying to teach myself using SQL
with parameters so I can head off some SQL injection attacks (that so far I have been
successful in stopping). I want to learn one step at a time, and so be able to access my
MS SQL 2005 database using parameters *before* I try creating a stored procedure.

Is "Transact SQL" the same thing as "SQL with parameters"?

Also, WHERE do I use/write Transact SQL? I see lots of code examples online, starting
with the DECLARE statement, but I do not know if I enter this in my ASP code, or if these
are stored procedure examples.

I am really a complete newbie to using parameters and I confess that a Google search for
parameters! The Microsoft reference is no help
(http://msdn.microsoft.com/en-us/library/ms189826%28SQL.90%29.aspx).

HELP!

Toni
ADODB.Command
(1)
SQL Server
(1)
Stored procedure
(1)
ADODB
(1)
AdVarWChar
(1)
VBScript
(1)
Database
(1)
CreateParameter
(1)
  Erland Sommarskog replied to Toni
18-Nov-09 06:51 PM
Toni (Toni24@yahoo.com) writes:

Transact-SQL is the SQL dialect that SQL Server users. No matter you
inline parameter values, or you parameterise your commands, you use
Transact-SQL (or T-SQL as it is commonly known as).


I cannot give an example of using parameterised commands in ASP, because
I have never worked with ASP. (By the way, ASP is a fairly old technology.
You should probably look at ASP .Net instead.)

But here is an example of using parameterised commands with ADO in
Visual Basic, which should be similar enough to VBscript:

Set cmd = CreateObject("ADODB.Command")
Set cmd.ActiveConnection = cnn

cmd.CommandType = adCmdText
cmd.CommandText = " SELECT OrderID, OrderDate, CustomerID, ShipName " & _
If custid <> "" Then
cmd.CommandText = cmd.CommandText & " AND CustomerID LIKE ? "
cmd.Parameters.Append
cmd.CreateParameter("@custid", adWChar, adParamInput, 5, custid)
End If

If shipname <> "" Then
cmd.CommandText = cmd.CommandText & " AND ShipName LIKE ? "
cmd.Parameters.Append cmd.CreateParameter("@shipname", _
adVarWChar, adParamInput, 40, shipname)
End If

Set rs = cmd.Execute






--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
  Toni replied to Erland Sommarskog
18-Nov-09 10:15 PM
Erland, thanks, but can you point me to any documentation that would help me understand
what you have written above, please???
  Erland Sommarskog replied to Toni
20-Nov-09 12:22 AM
Toni (Toni24@yahoo.com) writes:

The ? are parameter markers and are specific to the OLE DB and ODBC
API:s; they are not proper T-SQL. OLE DB and ODBC will transslate this
into proper T-SQL.

The Parameters collection is descibed here:
http://msdn.microsoft.com/en-us/library/ms675869%28VS.85%29.aspx

But the reference manual for ADO is not really written for people with
hardly no background knowledge, so it is not a good place to get started.
You need to click around a lot on the various links, to go CreateParameter
etc.

The ADO Programmer's Guide may be a better start, but I have not read it
myself. http://msdn.microsoft.com/en-us/library/ms681025%28VS.85%29.aspx.

Or you could get a book on ADO. David Datta wrote one many year's ago
that I liked: "Programming ADO". It may be hard to find, though. As I
said, ADO is yesterday's technology.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Create New Account
help
Behavior of ADODB.Command .Execute changes on different servers??? SQL Server Hello. We have an ASP 3.0 application that currently works "correctly" on one server, Server A, and we're testing it on another server, Server B, which is 64 bit. The connection string for Server A is: DRIVER = {SQL Server
Transactions in SQL Server Express SQL Server My VB6 project works fine with SQL Server 2000 and SQL Server 2005 databases located on servers without any modification. One client company uses SQL 2000, another
Outlook 2003 SQL Server 2005 SQL Server , SQL, Server, 2005" / > I was able to build the following code with the help of some help a rule in Outlook would read the properties of the new email and update a SQL Server 2005 database through a database connection. For example I would like to store and append
Outlook 2003 VBA SQL server 2005 Integration SQL Server , SQL, server, 2005, Integration" / > I was able to build the following code with the help of some a rule in Outlook would read the properties of the new email and update a SQL Server 2005 database through a database connection. For example I would like to store and append
SQL Server: 8, 421 max transactions per second? SQL Server i was wondering what an upper limit for SQL Server performance i should be looking at. i googled and found this article for SQL Server 2000: http: / / www.sqlmag.com / Article / ArticleID / 16087 / sql_server_16087.html 505, 302.77 transactions per