By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,036 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,036 IT Pros & Developers. It's quick & easy.

How do I correct this - Error Converting data type nvarchar to uniqueidentifier

P: 1
Dear Sirs,

My name is Joseph. I have a problem within my stored procedure that selects Userid and Password if the user's input fields are correct. I used Asp.net configuration functionality to build membership table in my database. However, in my membership table, UserId and Password datatypes are defined as uniqueidentifier and nVarchar, which were generated automatically when I used the Asp.net configuration functionality.

Now, in my login form, users are to input their UserId and Password, after entering the correct credentials. I am getting an error message - Conversion failed when converting from a character string to uniqueidentifier.

I am kindly asking you to assist me in debugging this problem. I have attach source code for your analysis.

Thanks.

Joseph
Function CheckCredentials(ByVal UId As String, ByVal Passwd As String) As Boolean 'System.Data.SqlClient.SqlDataReader

Dim blnUserIdPsd As Boolean = False
Dim UserName As String
Dim UserPswd As String

Dim strPwd As New Guid

Dim sqlCon As New System.Data.SqlClient.SqlConnection

sqlCon = establishsqlConnection()
sqlCommand = New System.Data.SqlClient.SqlCommand()

sqlCommand.CommandText = "Get_aspnet_roles_Credentials"
sqlCommand.Connection = sqlCon

sqlCommand.CommandType = CommandType.StoredProcedure
Dim dbparam_UserId As System.Data.SqlClient.SqlParameter = New System.Data.SqlClient.SqlParameter
dbparam_UserId.ParameterName = "@MyUserId"
dbparam_UserId.Value = UId
dbparam_UserId.SqlDbType = SqlDbType.NVarChar
dbparam_UserId.Direction = ParameterDirection.Input
sqlCommand.Parameters.Add(dbparam_UserId)

Dim dbparam_Passwd As System.Data.SqlClient.SqlParameter = New System.Data.SqlClient.SqlParameter
dbparam_Passwd.ParameterName = "@MyPassword"
dbparam_Passwd.Value = Passwd
dbparam_Passwd.SqlDbType = SqlDbType.NVarChar
dbparam_Passwd.Direction = ParameterDirection.Input
sqlCommand.Parameters.Add(dbparam_Passwd)
Dim provider As New DummyProvider()


Dim MyConversion As Guid
Dim reader As SqlClient.SqlDataReader
Dim rd As Integer
sqlCon.Open()
Try

reader = sqlCommand.ExecuteReader()

While (reader.Read())

UserName = reader.Item("UserId").ToString()
UserPswd = reader.Item("Password").ToString()
End While

If ((UId = UserName) And (Passwd = UserPswd)) Then
blnUserIdPsd = True

End If

Catch ex As Exception

blnUserIdPsd = False
End Try
Return blnUserIdPsd
End Function
End Class

Stored Porcedure:

USE [aspnetdb]
GO
/****** Object: StoredProcedure [dbo].[Get_aspnet_roles_Credentials] Script Date: 07/21/2010 11:34:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER
PROCEDURE [dbo].[Get_aspnet_roles_Credentials]
(
@MyUserId nVarchar (128),
@MyPassword nVarchar (128)

)
AS

BEGIN

Declare @guidUId uniqueidentifier
Declare @guidPwd nVarchar

Select @guidUId = CONVERT(uniqueidentifier, @MyUserId)

SELECT r.UserId, r.Password FROM dbo.aspnet_Membership r
Where r.UserId = @guidUId And r.Password = @MyPassword

END
Jul 21 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.