Use the SQL Server stored procedure to implement ASP user authentication

Source: Internet
Author: User
In the user authentication program, it is easy to use ASP to call SQL statements to retrieve records with matching conditions in the data table, and then use ASP for relevant processing.
All roads pass Rome! Of course, we can also use the stored procedures of the SQL SERVER database to easily implement this function. Although relatively complex, the efficiency improvement is obvious because the stored procedure is a program compiled in the database, we only need to use ASP to correctly pass the various parameters used by it.

This article also describes how to call a stored procedure with parameters in ASP through a simple example. I hope you can learn more from it.
Step 1: Create a data table userinfo
Id int (4) not null,
Fullname varchar (50) not null,
Password varchar (20) not null,
Nikename varchar (50) not null
Step 2: Create the stored procedure usercheck
CREATE procedure usercheck
@ Infullname varchar (50 ),
@ Inpassword varchar (50 ),
@ Outcheck char (3) OUTPUT
As
If exists (select * from userinfo where fullname = @ infullname and password = @ inpassword)
Select @ outcheck = 'yes'
Else
Select @ outcheck = 'no'
Note: a stored procedure with three parameters is created here. The first parameter @ infullname is an input parameter (username), and the second parameter @ inpassword is an input parameter, (password); third parameter @ outcheck, which is an OUTPUT parameter (whether the user exists). When defining an OUTPUT parameter, you must add "OUTPUT" after the data type.

Then, we take the first two input parameters to search for qualified users in the SQL statement. If yes, the output parameter value is "yes"; otherwise, it is "no ".

Step 3: compile an ASP program and call the stored procedure
<%
'Form submission flag
If request ("OK") = 1 then
'Establish a database connection
Set Comm = Server. CreateObject ("ADODB. Command ")
Comm. ActiveConnection = "DSN = localserver; UID = sa; PWD =; Database = chaiwei"
'Establish a stored procedure connection with the comm object. 4 indicates the connection type as the stored procedure.
Comm. CommandText = "usercheck"
Comm. CommandType = 4
'Use p1 as the name to create the parameter method of the comm object. Append the first parameter fullname to the p1 set.
'Fullname indicates the name of the first parameter called.
'2017 parameter type varchar
'1 parameter flow direction input, input is 1, output is 2
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.