Blog.Tools.ApplicationSetup.Program.MapUsersToIdentity C# (CSharp) Method

MapUsersToIdentity() private static method

private static MapUsersToIdentity ( ) : void
return void
		private static void MapUsersToIdentity()
		{
			var connectionstring = ConfigurationManager.AppSettings.Get("MasterDb");

			using (var con = new SqlConnection(connectionstring))
			{
				con.Open();

				#region sql command string
				const string sqlCommandText = @"
					declare @username varchar(max)
					declare @aspusers table 
					(
						username varchar(max),
						identityId varchar(max)
					)

					insert into @aspusers
					select username, id 
					from [blog_identity].[dbo].[aspnetusers]

					declare aspusers_cursor cursor for
					select username from @aspusers

					open aspusers_cursor
					fetch next from aspusers_cursor into @username   

					while @@FETCH_STATUS = 0   
					begin
						if exists (select * from [blog].[dbo].[users] where UserName = @username)
						begin
							update [blog].[dbo].[users] 
							set IdentityId = (select identityId from @aspusers where username = @username)
							where UserName = @username
						end
		
						fetch next from aspusers_cursor into @username   
					end   

					close aspusers_cursor   
					deallocate aspusers_cursor";
				#endregion

				var sqlCommand = new SqlCommand(sqlCommandText, con);
				sqlCommand.ExecuteNonQuery();
			}

			AddConsoleMessage("Successfully mapped users to identity...");
		}