Wednesday, November 27, 2019

Moving ASP.NET Session State Server to Aurora/MySQL

Our database was in MS SQL Server and we were in the middle of moving to Aurora with MySQL compatibility.

Problem

And obviously there are differences to be resolved and one of them is we are not sure on how to move the ASP.NET Session state.

Solution

After several troubleshooting sessions (pun not intended), I finally managed to move the session state server to Aurora. The following two webpages have been very helpful, albeit the first one is outdated:


My steps are as follow:

1. Disable the current state server by commenting/removing the sessionState tag under system.web in web.config.
2. Add MySql.Web Nuget package (As of this post, the working one is version 8.0.17).
3. Add new sessionState tag under system.web

<sessionState mode="Custom" customProvider="MySqlSessionStateStore"> 
   <providers> 
      <add name="MySqlSessionStateStore" type="MySql.Web.SessionState.MySqlSessionStateStore, MySql.Web, Version=8.0.17.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" applicationName="/" autogenerateschema="True" />
</providers> 
</sessionState>

Note the necessary attributes:

  • mode="Custom"
  • customProvider="<provider_name>"
  • autogenerateschema="True"
4. Add connection string. I would prefer to do this programmatically but I can't find a way to do it as of this post. Also, database has to be specified in the connection string.
5. Create schema/database in Aurora/MySql. I found out that MySql.Web doesn't automatically create the schema/database but it will generate necessary tables.

That is all to get it to work for me. 

Another thing to note is the autogenerateschema attribute was not available through autocomplete/intellisense. However, I can find some other attributes as properties of MySqlSessionStateStore class.



Install Previous Version of Nuget Package that is not Visible

Sometimes a new software version also introduces a new bug and we need to rollback. And this time is on one of the Nuget package that we use.

Problem

When troubleshooting MySql Nuget package issue, I noticed that I can't revert back to the previous version using the version drop down under Nuget manager window in Visual Studio. 

Solution

So, a bit of searching reminds me that I can use the Package Manager Console to install a package. Maybe I can specify the version and the server still has it. So I uninstall the latest package and ran the following command:

Install-Package <package_name> -Version <version> -Source nuget.org

The source option is optional. In my case, somehow I had it defaulted to some other source so I have to actually specify it in the command. Hit enter and I got the previous version installed. Problem solved!

Thursday, November 14, 2019

Convert FAT32 to NTFS with No Data Loss in Windows

Filesystem is as usual a pretty complicated thing. And I happened to have a new external hard drive that for somewhat reason was formatted as FAT32. Of course, I didn't notice until I put a bunch of data in it. 

Problem

The time has come when I need to store file larger than the 4GB limit of FAT32. 

Solution

So browsing around the internet, I found out that I can convert to NTFS without data loss and third party software from https://www.tenforums.com/tutorials/85893-convert-fat32-ntfs-without-data-loss-windows.html.

The steps that I took are:

  1. Make sure data are backed up somewhere else.
  2. Close all software/application that has the drive opened. I closed the File Explore too.
  3. Run command prompt as administrator.
  4. Run the following command in command prompt: convert <drive> /fs:ntfs. For example: convert D: /fs:ntfs
  5. Restart the computer.
That's it!



Wednesday, November 13, 2019

Kernel not Updated on Ubuntu 14.04 in AWS EC2 Nitro-based Instance

Sometimes a simple thing which works for many others doesn't work for us and this time it is on updating the Linux kernel.

Problem

It is all started when we are trying to migrate an m1 to t3. We are aware that t3 is a Nitro-based instance thus NVMe and ENA module have to be installed. Even after following AWS documentation, the modules don't seem to be installed properly even after reboot. Then the journey begins.

 First, I ran the following command to check what kernel is actually loaded:

uname -r

In this particular case, it returns: 3.13.0-45-generic. And I know that it is not the latest. So, as suggested by Amazon support, I ran the following commands one by one to see if the latest linux-aws package are properly installed and at the latest and nvme driver is loaded into the kernel (NVME driver is set to 'Y') 

sudo apt-cache policy linux-aws

ls -al /boot/

cat /boot/config-4.4.0-1044-aws |grep -i "nvme"


And the result are all as expected. The latest kernel is installed and nvme driver is loaded, but somehow the latest kernel is not used. I ran the following command to confirm.

dpkg -l | grep 'linux-image-'

On the amazon kernel, it starts with ii so it is indeed properly installed. Searching more online, some people manage to get the latest kernel installed and loaded using a combination of the following commands:

sudo apt-get update (update packages)

sudo apt-get install linux-generic (install meta package which was missing from my instance)

sudo apt-get install --reinstall linux-image-4.4.0-1044-aws (replace the last part with the latest kernel to reinstall)

sudo apt-get autoremove (clean up)

sudo apt-get install -f (force install missing packages)

update-grub (update grub)

None seems to work for me. 

Solution

After several days, I was wondering if somehow it has something to do with grub. So I start checking the result of the update-grub command and found out that it tries to update /boot/grub/menu.lst. That means it is using grub-legacy. So, I ran the command to check for the content menu.lst:

cat /boot/grub/menu.lst

To my surprise, none of the latest kernels are actually configured in there. In other words, the menu.lst is not updated properly. Few more online search brought me to the following article https://ubuntuforums.org/showthread.php?t=873448. Seems like there is a case which will trigger a bug. Hence menu.lst is not updated. So I make a quick copy and re-run update-grub.

cp /boot/grub/menu.lst /boot/grub/menu.lst.bak
rm /boot/grub/menu.lst
update-grub

And checking the menu.lst once again results in the latest kernel being updated in there. Restarting the instance and voilĂ ! The latest kernel is loaded and converting it to t3 was successful.