Asp SQL Injection Prevention Method

Source: Internet
Author: User
Tags sql injection prevention

Next we will introduce another method to prevent SQL injection attacks in ASP. This method is not only applicable in ASP, but can be used in any language that uses ADO object models to interact with databases, to be accurate, it is more appropriate to call the method of anti-SQL Injection Based on the ADO object model. Okay. Let's take a look at the code. Copy codeThe Code is as follows: Dim conn, cmd
Set conn = server. createobject ("adodb. connection ")
Conn. Open "............ "'The database connection word is omitted here

Set cmd = server. createobject ("adodb. Command ")
Set upa = server. createobject ("adodb. Parameter ")
Cmd. ActiveConnection = conn

Cmd. CommandText = "update news set title =? Where id =? "
Cmd. CommandType = ad1_text

Set upa = cmd. CreateParameter ("title", adVarWChar, adParamInput, 50, "1 '2' 3 ")
Cmd. Parameters. Append HPA

Set upa = cmd. CreateParameter ("id", adInteger, adParamInput, 10)
Cmd. Parameters. Append HPA

Cmd. Execute

The id field of the news table is Integer, and the title field is nvarchar (50, the result of execution is to change the content of the title field of the record with the id field 10 in the news table to "1 '2' 3"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.