Call SQL Server Database Storage Process Realization ASP User Authentication

xiaoxiao2021-03-06  38

In we write user authentication programs, it is easy to call the SQL statement with the ASP to retrieve the records in the data table, and then use the ASP to perform relevant processing.

Article road Tong Rome! Of course, we can also easily implement this feature with the stored procedure of the SQL Server database. Although it is relatively complicated, its efficiency is significant, because the stored procedure is a program that has been compiled in the database, and we only need to use ASP to pass it correctly.

This article is mainly to tell you how to call the parameters in the ASP in ASP. I hope everyone can get more enlightenment from it.

First step, build 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, establish a 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: The stored procedure with three parameters is established, the first parameter @infullname, this is an input parameter, (username); second parameter @inpassword, is also an input parameter, (password); third Parameters @outcheck, this is an output parameter, (if this user exists), when defining the output parameter, you must add "OUTPUT" after the data type, the words.

Then, we bring the first two input parameters to retrieve whether there is a qualified user in the SQL statement. If there is, the value of the output parameter is "YES", otherwise "no".

In the third step, write the ASP program, call the stored procedure

<%

'Form submission sign

IF Request ("OK") = 1 THEN

'Establish a database connection

SET COMM = Server.createObject ("AdoDb.command")

Comm .activeConnection = "DSN = localserver; uid = sa; pwd =; database = chaiwei"

'Set up a stored procedure connection with a CommM object, 4 represents the type of connection is a stored procedure.

Comm.commandtext = "UserCheck"

Comm.commandtype = 4

'Prameter method for establishing a Comm-object with P1 for the name. Add the first parameter fullname to the P1 collection

The name of the first parameter called by 'fullname

'200 Parameter Type VARCHAR

'1 parameter flows to input, input to 1, output is 2

'50 parameter length 50

'Request ("fullname") assignment parameter outset

Set P1 = Comm.createParameter ("Fullname", 200, 1, 50, Request ("fullname")) comm.parameters.Append P1

'Prameter method for establishing a Comm-object with P1 for the name. Add a second parameter password to the P1 collection

'Specific same

Set P1 = Comm.CreateParameter ("Password", 200, 1, 20, Request ("Password"))

Comm.Parameters.Append P1

'Prameter method for establishing a Comm-object with P1 for the name. Add the third parameter Check to the P1 collection

'129 parameter type CHAR type

'2 parameter flow to output

'3 parameter length 3

Set p1 = comm.createparameter ("Check", 129, 2, 3)

Comm.Parameters.Append P1

'Run stored procedure

Comm.execute

'Propose the result, process

IF Comm ("Check") = "Yes" then

"Welcome to the system! Username:" & Comm ("fullname") & "Password:" & comm ("password")

Else

"Sorry, you have not registered!"

END IF

'Release connection

SET COMM = Nothing

Else

'Form part

%>

<%

END IF

%>

转载请注明原文地址:https://www.9cbs.com/read-66048.html

New Post(0)