Xadeu
Starting Member
2 Posts |
Posted - 2007-08-22 : 13:19:42
|
Greetings Everyone!!!I have a SQLEXPRESS Server on which I created a database named WebApp. I am trying to add a statement to dbo.aspnet_Membership_CreateUser which is contained in the ASPNETDB database which is located at C:\<AppName>\App_Data\ASPNETDB.MDF (I attached this database to SQLEXPRESS to modify the said stored procedure.) I want Membership_CreateUser to update a table in WebApp.dbo.UserInformation, I simply want to insert the username of the user that was just created as a record into UserInformation. This is the exact statement I use:INSERT INTO [SSI0700\SQLEXPRESS].WebApp.dbo.UserInformation(UserName) VALUES (@UserName)I keep getting this error."Could not find server 'SSI0700\SQLEXPRESS' in sys.servers. Verify that the correct server name was specified. If necessary, execute stored procedure sp_addlinkedserver to add the server to sys.servers."But I have checked sys.servers and the record for 'SSI0700\SQLEXPRESS' is the only record in the table. Any thoughts or suggestions would be very helpful!UPDATE:I found that if I remove the [SSI0700\SQLEXPRESS] from the INSERT statement that I now get this error:Invalid object name 'WebApp.dbo.UserInformation'.Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 0, current count = 1.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.This is my edit of the stored procedure command as it currently is (my changes start at --Xadeu edit--):set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoALTER PROCEDURE [dbo].[aspnet_Membership_CreateUser]@ApplicationName nvarchar(256),@UserName nvarchar(256),@Password nvarchar(128),@PasswordSalt nvarchar(128),@Email nvarchar(256),@PasswordQuestion nvarchar(256),@PasswordAnswer nvarchar(128),@IsApproved bit,@CurrentTimeUtc datetime,@CreateDate datetime = NULL,@UniqueEmail int = 0,@PasswordFormat int = 0,@UserId uniqueidentifier OUTPUTASBEGINDECLARE @ApplicationId uniqueidentifierSELECT @ApplicationId = NULLDECLARE @NewUserId uniqueidentifierSELECT @NewUserId = NULLDECLARE @IsLockedOut bitSET @IsLockedOut = 0DECLARE @LastLockoutDate datetimeSET @LastLockoutDate = CONVERT( datetime, '17540101', 112 )DECLARE @FailedPasswordAttemptCount intSET @FailedPasswordAttemptCount = 0DECLARE @FailedPasswordAttemptWindowStart datetimeSET @FailedPasswordAttemptWindowStart = CONVERT( datetime, '17540101', 112 )DECLARE @FailedPasswordAnswerAttemptCount intSET @FailedPasswordAnswerAttemptCount = 0DECLARE @FailedPasswordAnswerAttemptWindowStart datetimeSET @FailedPasswordAnswerAttemptWindowStart = CONVERT( datetime, '17540101', 112 )DECLARE @NewUserCreated bitDECLARE @ReturnValue intSET @ReturnValue = 0DECLARE @ErrorCode intSET @ErrorCode = 0DECLARE @TranStarted bitSET @TranStarted = 0IF( @@TRANCOUNT = 0 )BEGINBEGIN TRANSACTIONSET @TranStarted = 1ENDELSESET @TranStarted = 0EXEC dbo.aspnet_Applications_CreateApplication @ApplicationName, @ApplicationId OUTPUTIF( @@ERROR <> 0 )BEGINSET @ErrorCode = -1GOTO CleanupENDSET @CreateDate = @CurrentTimeUtcSELECT @NewUserId = UserId FROM dbo.aspnet_Users WHERE LOWER(@UserName) = LoweredUserName AND @ApplicationId = ApplicationIdIF ( @NewUserId IS NULL )BEGINSET @NewUserId = @UserIdEXEC @ReturnValue = dbo.aspnet_Users_CreateUser @ApplicationId, @UserName, 0, @CreateDate, @NewUserId OUTPUTSET @NewUserCreated = 1ENDELSEBEGINSET @NewUserCreated = 0IF( @NewUserId <> @UserId AND @UserId IS NOT NULL )BEGINSET @ErrorCode = 6GOTO CleanupENDENDIF( @@ERROR <> 0 )BEGINSET @ErrorCode = -1GOTO CleanupENDIF( @ReturnValue = -1 )BEGINSET @ErrorCode = 10GOTO CleanupENDIF ( EXISTS ( SELECT UserIdFROM dbo.aspnet_MembershipWHERE @NewUserId = UserId ) )BEGINSET @ErrorCode = 6GOTO CleanupENDSET @UserId = @NewUserIdIF (@UniqueEmail = 1)BEGINIF (EXISTS (SELECT *FROM dbo.aspnet_Membership m WITH ( UPDLOCK, HOLDLOCK )WHERE ApplicationId = @ApplicationId AND LoweredEmail = LOWER(@Email)))BEGINSET @ErrorCode = 7GOTO CleanupENDENDIF (@NewUserCreated = 0)BEGINUPDATE dbo.aspnet_UsersSET LastActivityDate = @CreateDateWHERE @UserId = UserIdIF( @@ERROR <> 0 )BEGINSET @ErrorCode = -1GOTO CleanupENDENDINSERT INTO dbo.aspnet_Membership( ApplicationId,UserId,Password,PasswordSalt,Email,LoweredEmail,PasswordQuestion,PasswordAnswer,PasswordFormat,IsApproved,IsLockedOut,CreateDate,LastLoginDate,LastPasswordChangedDate,LastLockoutDate,FailedPasswordAttemptCount,FailedPasswordAttemptWindowStart,FailedPasswordAnswerAttemptCount,FailedPasswordAnswerAttemptWindowStart )VALUES ( @ApplicationId,@UserId,@Password,@PasswordSalt,@Email,LOWER(@Email),@PasswordQuestion,@PasswordAnswer,@PasswordFormat,@IsApproved,@IsLockedOut,@CreateDate,@CreateDate,@CreateDate,@LastLockoutDate,@FailedPasswordAttemptCount,@FailedPasswordAttemptWindowStart,@FailedPasswordAnswerAttemptCount,@FailedPasswordAnswerAttemptWindowStart )IF( @@ERROR <> 0 )BEGINSET @ErrorCode = -1GOTO CleanupEND--Xadeu Edit: Adding the new user's username into the UserInformation table here--so that if anything in the User Creation Process fails we can rollback everything--at once.INSERT INTO WebApp.dbo.UserInformation(UserName) VALUES (@UserName)--INSERT INTO [SSI0700\SQLEXPRESS].WebApp.dbo.UserInformation(UserName) VALUES (@UserName)--select * from WebApp..UserInformationIF( @@ERROR <> 0 )BEGINSET @ErrorCode = -1GOTO CleanupEND--DONE WITH Xadeu EDIT--IF( @TranStarted = 1 )BEGINSET @TranStarted = 0COMMIT TRANSACTIONENDRETURN 0Cleanup:IF( @TranStarted = 1 )BEGINSET @TranStarted = 0ROLLBACK TRANSACTIONENDRETURN @ErrorCodeENDThanks, Xadeu |
|