P
Patrick
sorry if this is a repsot, but I can't see my 1st post. Lost my connection
in the middle of posting
I don't know what's happening here. I can run the sp in query analyzer and
(using PRINT) see that it returns a positive record number. But when I run
this function on that sp it returns -1. I used EM's SQL profiler and can see
that it's returning -1, there, too. But the same inputs in query analyzer
returns 2, a passing authenticate. How can I see what's being sent to SQL
server? I have SQL debugger turned on, but ...
Function DBAuthenticate( strUsername As String, strPassword As String ) As
Integer
Dim conMyData As SqlConnection
Dim cmdSelect As SqlCommand
Dim parmReturnValue As SqlParameter
Dim intResult As Integer
conMyData = New SqlConnection("workstation id=W2000;packet
size=4096;integrated security=SSPI;data source=W2000;" & _
"persist security info=False;initial catalog=trythis")
cmdSelect = New SqlCommand( "DBAuthenticate", conMyData )
cmdSelect.CommandType = CommandType.StoredProcedure
parmReturnValue = cmdSelect.Parameters.Add( "RETURN_VALUE",
SqlDbType.Int )
parmReturnValue.Direction = ParameterDirection.ReturnValue
cmdSelect.Parameters.Add( "@username", strUsername )
cmdSelect.Parameters.Add( "@password", strPassword )
conMyData.Open()
cmdSelect.ExecuteNonQuery()
intResult = cmdSelect.Parameters( "RETURN_VALUE" ).Value
conMyData.Close()
If intResult < 0 Then
If intResult = -1 Then
lblMessage.Text = "Username Not Registered!"
Else
lblMessage.Text = "Invalid Password!"
End If
End If
Return intResult
End Function
This code is from Sam's ASP.Net Unleashed 2nd edition. I've had to tweak a
few other things, but this looks like it should work.
TIA,
Patrick
psully at eatel dot net
ps: here's the sp
CREATE PROCEDURE DBAuthenticate
(
@username Varchar( 100 ),
@password Varchar( 100 )
)
As
DECLARE @ID INT
DECLARE @actualPassword Varchar( 100 )
SELECT
@ID = IdentityCol,
@actualPassword = u_password
FROM UserList
WHERE u_username = @username
IF @ID IS NOT NULL
IF @password = @actualPassword
RETURN @ID
ELSE
RETURN - 2
ELSE
RETURN - 1
GO
in the middle of posting
I don't know what's happening here. I can run the sp in query analyzer and
(using PRINT) see that it returns a positive record number. But when I run
this function on that sp it returns -1. I used EM's SQL profiler and can see
that it's returning -1, there, too. But the same inputs in query analyzer
returns 2, a passing authenticate. How can I see what's being sent to SQL
server? I have SQL debugger turned on, but ...
Function DBAuthenticate( strUsername As String, strPassword As String ) As
Integer
Dim conMyData As SqlConnection
Dim cmdSelect As SqlCommand
Dim parmReturnValue As SqlParameter
Dim intResult As Integer
conMyData = New SqlConnection("workstation id=W2000;packet
size=4096;integrated security=SSPI;data source=W2000;" & _
"persist security info=False;initial catalog=trythis")
cmdSelect = New SqlCommand( "DBAuthenticate", conMyData )
cmdSelect.CommandType = CommandType.StoredProcedure
parmReturnValue = cmdSelect.Parameters.Add( "RETURN_VALUE",
SqlDbType.Int )
parmReturnValue.Direction = ParameterDirection.ReturnValue
cmdSelect.Parameters.Add( "@username", strUsername )
cmdSelect.Parameters.Add( "@password", strPassword )
conMyData.Open()
cmdSelect.ExecuteNonQuery()
intResult = cmdSelect.Parameters( "RETURN_VALUE" ).Value
conMyData.Close()
If intResult < 0 Then
If intResult = -1 Then
lblMessage.Text = "Username Not Registered!"
Else
lblMessage.Text = "Invalid Password!"
End If
End If
Return intResult
End Function
This code is from Sam's ASP.Net Unleashed 2nd edition. I've had to tweak a
few other things, but this looks like it should work.
TIA,
Patrick
psully at eatel dot net
ps: here's the sp
CREATE PROCEDURE DBAuthenticate
(
@username Varchar( 100 ),
@password Varchar( 100 )
)
As
DECLARE @ID INT
DECLARE @actualPassword Varchar( 100 )
SELECT
@ID = IdentityCol,
@actualPassword = u_password
FROM UserList
WHERE u_username = @username
IF @ID IS NOT NULL
IF @password = @actualPassword
RETURN @ID
ELSE
RETURN - 2
ELSE
RETURN - 1
GO