C ++ builder learn how to use stored procedures to prevent repeated login by the same person!

Source: Internet
Author: User

// Stored Procedure

/* If Exists (select name from sysobjects where name = 'addonearticle' and type = 'P') drop procedure addOneArticle */
/* If Exists (select name from sysobjects where name = 'session' and type = 'P') drop procedure Session */
/* Exec ('drop procedure dbo. session ')*/
Use highway_test_new
Set ANSI_NULLS ON
Set QUOTED_IDENTIFIER ON
If Exists (select id from dbo. sysobjects where id = object_id ('dbo. session') and type = 'P ')
BEGIN
Exec ('drop procedure dbo. session ')
Return
END

GO
Create procedure Session
@ Username varchar (50), @ I _result INT OUTPUT
AS
BEGIN
DECLARE @ v_ SQL varchar (200)
If object_id ('tempdb. DBO. # user' + @ username) is null
Begin
Set @ v_ SQL = 'create table # user' + @ username + '(username varchar (100 ))'
Exec (@ v_ SQL)
Set @ I _result = 0
End
Else
Set @ I _result = 1
End
//

Implementation Code

Bool verifyuserlogin (tmsconnection * pconn, tmsstoredproc * ptsp, ansistring strusername)
{
If (pConn = NULL | ptsp = NULL)
Return false;
Ptsp-> StoredProcName = "Session ";
Ptsp-> Connection = pConn;
Ptsp-> ParamByName ("@ username")-> AsString = strUserName;
Ptsp-> ExecProc ();
Int iRet;
IRet = ptsp-> ParamByName ("@ I _result")-> AsInteger;
If (iRet = 1) // the same user is logged on
{
Return false;
}
Else if (iRet = 0)
{
Return true;
}
Return false;
}

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.