Restore deleted ASP.net user membership

If you accidentally delete asp.net user from membership using this code Membership.DeleteUser but you have a backup of your previous database then you can restore it using the following sql.
assume :
 your current database name is MYDB and your previous database name is MYDB2.
 you must know the userid of the deleted user. you can get the userid using this code
   select * from MYDB2.dbo.aspnet_users where username like '%somename%'

USE [MYDB]
GO
/****** Object:  StoredProcedure [dbo].[RestoreMembershipDeleteUser]    Script Date: 10/19/2010 11:23:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE proc [dbo].[RestoreMembershipDeleteUser](@userid uniqueidentifier)
as
begin

if not exists (select * from MYDB2.dbo.aspnet_users where userid=@userid) 
begin
    print 'userid not found in prev aspnet_users'
    return 0
end
if not exists (select * from MYDB2.dbo.aspnet_membership where userid=@userid) 
begin
    print 'userid not found in prev aspnet_membership'
    return 0
end
--get information from backup database
--MYDB2 is the backup database
declare @ApplicationId uniqueidentifier
declare @UserName nvarchar(256)
declare @Email nvarchar(256)
declare @CreateDate datetime
declare @Password   nvarchar(128)
declare @PasswordSalt  nvarchar(128)
declare @IsApproved bit
declare @IsLockedOut bit
declare @LastLoginDate datetime
declare @FailedPasswordAttemptCount int
declare @FailedPasswordAttemptWindowStart datetime
declare @FailedPasswordAnswerAttemptCount int
declare @FailedPasswordAnswerAttemptWindowStart datetime
declare @LastPasswordChangedDate datetime
declare @LastLockoutDate datetime
declare @LastActivityDate datetime

select @UserName = username from MYDB2.dbo.aspnet_users where userid=@userid
select
    @ApplicationId = Applicationid,
    @Email = email,    
    @CreateDate =CreateDate,
    @Password=Password,
    @PasswordSalt=PasswordSalt,
    @IsApproved = IsApproved,
    @IsLockedOut = IsLockedOut,
    @LastLoginDate = LastLoginDate,
    @LastPasswordChangedDate = LastPasswordChangedDate,
    @LastLockoutDate = LastLockoutDate,
    @FailedPasswordAttemptCount = FailedPasswordAttemptCount,
    @FailedPasswordAttemptWindowStart = FailedPasswordAttemptWindowStart,
    @FailedPasswordAnswerAttemptCount = FailedPasswordAnswerAttemptCount,
    @FailedPasswordAnswerAttemptWindowStart = FailedPasswordAnswerAttemptWindowStart
from MYDB2.dbo.aspnet_membership
where userid=@userid

declare @TranStarted   bit

set @TranStarted = 0
if( @@TRANCOUNT = 0 )
begin
  begin transaction       
  set @TranStarted = 1
end
else
    set @TranStarted = 0
   
--delete existing data   
delete from aspnet_Membership WHERE UserID = @userid
if( @@ERROR <> 0 )
begin     
    print 'error delete aspnet_Membership'
    goto Cleanup
end 
 
delete from aspnet_Users WHERE UserID = @userid
if( @@ERROR <> 0 )
begin     
    print 'error delete aspnet_Users'
    goto Cleanup
end  

declare @ReturnValue int
EXEC @ReturnValue = dbo.aspnet_Users_CreateUser @ApplicationId, @UserName, 0, @CreateDate, @UserId OUTPUT
if( @@ERROR <> 0 or @ReturnValue = -1)
begin     
    print 'error exec aspnet_Users_CreateUser'
    goto Cleanup
end  

if not exists (select * from aspnet_Membership where userid=@userid)
begin
 INSERT INTO aspnet_Membership
                ( ApplicationId,
                  UserId,
                  Password,
                  PasswordSalt,
                  Email,
                  LoweredEmail,
                  IsApproved,
                  IsLockedOut,
                  CreateDate,
                  LastLoginDate,
                  LastPasswordChangedDate,
                  LastLockoutDate,
                  FailedPasswordAttemptCount,
                  FailedPasswordAttemptWindowStart,
                  FailedPasswordAnswerAttemptCount,
                  FailedPasswordAnswerAttemptWindowStart
                  )
    values
        (@applicationid,
        @userid,
        @Password,
        @PasswordSalt,
        @email,
        lower(@email),
        @IsApproved,
        @IsLockedOut,
        @CreateDate,
        @LastLoginDate,
        @LastPasswordChangedDate,
        @LastLockoutDate,
        @FailedPasswordAttemptCount,
        @FailedPasswordAttemptWindowStart,
        @FailedPasswordAnswerAttemptCount,
        @FailedPasswordAnswerAttemptWindowStart)
    if( @@ERROR <> 0 )
    begin     
        print 'error insert aspnet_Membership'
        goto Cleanup
    end        
end

if( @TranStarted = 1 )
begin
    set @TranStarted = 0
    COMMIT TRANSACTION
end

    return 0
Cleanup:

    IF( @TranStarted = 1 )
    BEGIN
        SET @TranStarted = 0
        print 'rollback'
        ROLLBACK TRANSACTION
    END

    RETURN -1
end

Poken, a business card replacement



POKEN is a cute little gadget designed to make sharing your social networking contact details a lot easier. In essence, POKEN is really a modern day version of the business card. Just hold 2 of them together and you’ll be connected through all of the social networks you already use such as Facebook, Twitter, LinkedIn and 45 others. In Japan and Europe these little guys have already become very popular. Now they are finally available in the U.S. for $20 a pop. There are two kinds of POKENs. First there is the adorable “the Spark” which comes in an adorable design including a Geisha, a Rap Star a Panda Bear and an Alien. The second type is the pokenPULSE which looks much like an ordinary USB key and it also has 2GB of memory. But despite the fact that the pokenPULSE resembles an ordinary USB key, it actually isn’t drab at all – it comes in several colorful designs, but you have to remove its cap to actually see the designs. source

Microsoft Office: The Movie


Here is the new Microsoft Office 2010 The Movie. It's very funny :))

Google Book Downloader


Google Book Downloade Screenshot

Google Book Downloader is small utility which allows you to save book from google book to your local filesystem as image file (jpg or png). First you have to download it from Google Book Downloader.  All you have to do is just enter the book url on text box and select an empty folder to save the downloaded images, then press Go button. After the book is loaded in the browser, you have to scroll the book’s page till the end of page. The Google Book Downloader will copy the images of each page from your browser cache to specified folder.

Creating MP3 Media Player Using MFC and FMod


FMod Media Player
Do you want to create MP3 player using free library?? Then I suggest you to use FMod. It's free and support almost all musics file formats (wav, mp2, mp3, ogg, wma, raw, mid, mod, s3m, it, xm, fsb, rmi, sgt). The documentation is quite complete and easy to use. But if you need more detail example of how creating MP3 player or audio player using FMod then I suggest you to look into my previous work. Here is the MFC source code and the demo application