我在我的网站上使用asp.net的内置角色和会员管理工具。我目前正在升级网站的功能,以便网站管理员可以添加/删除角色,并管理网站内页面内不同角色的访问权限。但是,当我执行
时System.Web.Security.Roles.CreateRole(roleName); //Where roleName is a string value of the role that I am creating, and it is not a duplicate name.
我收到错误消息
System.Data.SqlClient.SqlException: Conversion failed when converting from a character string to uniqueidentifier.
该站点在共享主机上运行,我正在使用ASP.NET表,触发器和存储过程。奇怪的是,我使用内置方法将用户更新为角色,创建用户,删除用户,重置密码等都没有遇到任何问题。是否有可能系统为我创建的存储过程存在某些缺陷并且没有返回它需要执行的所有数据?如果没有,那么还有什么可能是问题的原因?
答案 0 :(得分:1)
答案 1 :(得分:1)
这是创建角色SP:
CREATE PROCEDURE [dbo].[aspnet_Roles_CreateRole]
@ApplicationName nvarchar(256),
@RoleName nvarchar(256)
AS 开始 DECLARE @ApplicationId uniqueidentifier SELECT @ApplicationId = NULL
DECLARE @ErrorCode int
SET @ErrorCode = 0
DECLARE @TranStarted bit
SET @TranStarted = 0
IF( @@TRANCOUNT = 0 )
BEGIN
BEGIN TRANSACTION
SET @TranStarted = 1
END
ELSE
SET @TranStarted = 0
EXEC dbo.aspnet_Applications_CreateApplication @ApplicationName, @ApplicationId OUTPUT
IF( @@ERROR <> 0 )
BEGIN
SET @ErrorCode = -1
GOTO Cleanup
END
IF (EXISTS(SELECT RoleId FROM dbo.aspnet_Roles WHERE LoweredRoleName = LOWER(@RoleName) AND ApplicationId = @ApplicationId))
BEGIN
SET @ErrorCode = 1
GOTO Cleanup
END
INSERT INTO dbo.aspnet_Roles
(ApplicationId, RoleName, LoweredRoleName)
VALUES (@ApplicationId, @RoleName, LOWER(@RoleName))
IF( @@ERROR <> 0 )
BEGIN
SET @ErrorCode = -1
GOTO Cleanup
END
IF( @TranStarted = 1 )
BEGIN
SET @TranStarted = 0
COMMIT TRANSACTION
END
RETURN(0)
清理:
IF( @TranStarted = 1 )
BEGIN
SET @TranStarted = 0
ROLLBACK TRANSACTION
END
RETURN @ErrorCode
END