Friday, June 17, 2022

Resolving MSB3247 - Found conflicts between different versions of the same dependent assembly

Sometime back I got a warning in Visual Studio 2019 to the effect captured in the title of this post. I followed a suggestion from StackOverflow to diagnose the cause of this error and turned on the verbose diagnostic of the MSBuild tool. As far as I could understand, the cause of the error was different DLL versions that some packages depended upon. It's not possible to have multiple versions of .NET Framework DLLs on the same machine. Then I hit upon the following link while googling the Internet

The fix was as simple as running Update-Package -reinstall in the Package Manager Console of VS 2019.

Wednesday, June 8, 2022

SQL Server error: 52 - Unable to locate a Local Database Runtime installation

The title of this post is a cryptic error message that I got when trying to use EntityFramework 6 (EF6 - .NET Framework, not EF Core) in an ASP.NET MVC 5 (not ASP.NET Core). The context of the usage is when I was trying to update the database in Nuget PackageManager console with the following command:

Update-Database

I looked at the connection string hard and wrestled with it for many hours up to no avail. The reason was that the rest of the error message said that there was a failure to connect to SQL Server and naturally the reason for my wrestling with the connection string was the hope of connecting with the SQL Server.

Strangely, the SQL Server Management Studio was able to connect with the SQL Server instance with the same username and password. And, so could the Visual Studio Server Explorer. In fact, I also tried copying the connection string from the Visual Studio Server Explorer Advanced Settings for the SQL Server instance. Nothing worked. Then it flashed to me that there must be something wrong with the way we are setting up the EntityFramework migration of the database. We reinstalled the EntityFramework package and issued the following commands in the PackageManager console:

Enable-Migration

Add-Migration Initial

Update-Database

This also didn't work!!

Finally I saw that the subclass of DbContext class that was declared in the project wasn't calling the base class's (DbContext class) constructor:

public AppDbContext : DbContext
{
  public AppDbContext() : base("name=ConnectionString")
  { }
}

Putting the above constructor finally made the update-database command work. The name=ConnectionString is the name attribute of the XML element in web.config that has the connection string of the database. Great Lord! We went through such hoops and loops to get this to work and the solution lay somewhere else.

Tuesday, June 7, 2022

SQL Server Management Studio With SQL Server inside a docker container

Recently, I downloaded the docker image for SQL Server and wanted to connect to the server via the excellent SQL Server Management Studio. The docker container was run using the following commands

For downloading the SQL Server image:

docker pull mcr.microsoft.com/mssql/server:2019-latest

For setting up the SQL Server and running it:

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<YourStrong@Passw0rd>" -p 6433:1433 --name sql1 --hostname sql1 -d mcr.microsoft.com/mssql/server:2019-latest

Note that the SQL Server port 1433 has been mapped to port 6433 on the host. This was done because   I already had a SQL server installed on my laptop running at port 1433 which I didn't want to disturb. All this stuff can be read in detail here.

What now remained was to point the SQL Server Management Studio to this SQL Server instance running inside a container. In the "Connect To Server" dialog, the server name was specified as localhost,6433. Authentication: SQL Server Authentication. Username: sa and Password: <YourStrong@Passw0rd>

Some more references:

1. Deploying and running queries on SQL Server in Docker.

2. Connecting Management Studio to SQL Server running on a non-standard port.

Saturday, June 4, 2022

DateTime format issues in ASP.NET

There was a prolonged ongoing problem resolution effort in our workplace. It was a mysterious problem that had us all stumped. The problem was DateTime parsing. Strings containing dates were not being parsed "properly" on the server. The same strings were being parsed perfectly when the server program ran on our local computers.

We first checked the date format on the server. The format was changed to match our local machines - "dd/MMM/yyyy". The country/region was set to "India" and the regional format was set to "English (India)". In spite of these changes, the web app behaved differently on the server machine when compared to how it behaved on our machines (laptops and desktops). Then we took a look at the "Current System Locale" setting - buried under Settings -> Region -> Additional date, time & regional settings -> Change date, time or number formats -> Administrative -> Change system locale. However, this was set to English(United States) on both our machines and the server. This meant that this setting was not the cause of the different behavior. The fact that the server OS was Windows 2016 Server edition might be making the difference. But, how do we fix the date-time issue?

Finally, after some googling, I found the following stackoverflow article. Inserting the following XML snippet in the <configuration><system.web> fixed the issue: 

 <globalization uiCulture="en-IN" culture="en-IN" />

Saturday, February 25, 2012

Fixing Windows 7 MBR overwritten by Grub2

Dear Readers,
All glories to Srila Prabhupada.
Recently I faced the problem of having the MBR of my IDE HDD being overwritten by Grub2. I found an article describing the recovery process: http://support.microsoft.com/kb/927392. Unfortunately when I tried that, the System Recovery Options window was not listing any OS! I figured out that I had to disable my other HDD (on which Linux - Debian was installed) and retry. This time I could see the Windows 7 installation listed in the recovery window. Startup Repair options didn't work and I had to resolve to opening the command prompt and using bootrec.exe. All I had to type at the command prompt was

C:
cd boot
bootrec /FixMbr


Maybe the first two lines are not even required!.
Done by the mercy of Sridharaswamy Maharaja.

Thursday, February 23, 2012

gjig errors revealing

Jai Srila Prabhupada

When I tried running gjig as root, I learned a few things about running graphical programs as root. The method of using 'su' to become root is only relevant if the program is non-graphical (doesn't use X11). The right way is to use gksu.

Om namo bhagavate sridharaya

Monday, February 6, 2012

Switching to a pseudo-terminal in Debian

Ctrl+Alt+F, where n >= 1 AND n <=8. Usually Gnome desktop runs at n=8 (tty8)

Om namo shridaraya

Resolving "Could not update ICEAuthority /var/lib/gdm3

Here is the error message that you might encounter before logging into gnome desktop:
Could not update .ICEauthority file  /var/lib/gdm3/.ICEauthority
I have resolved this problem by simply removing that file and let gdm3 daemon re-create it. The commands below must be executed with root privileges.
/etc/init.d/gdm3 stop rm /var/lib/gdm3/.ICEauthority* /etc/init.d/gdm3 start 
perform the above steps from another pseudo terminal (the terminal in which the gnome desktop runs is tty8)


Om namo shridharaya

Sunday, February 5, 2012

Enabling the ability to view Kannada on Linux

Need to install ttf-kannada-fonts package. This package enables us to view text displayed in kedage and mallige fonts. Additional packages may have to be installed for viewing text in other fonts.

Om namo sridharaya.

Sunday, December 18, 2011

DataTable doesn't support CheckState values

DataTable (related to DataSet) doesn't parse CheckState values when a column of CheckState data type is added using the Visual Studio designer.

Friday, December 16, 2011

Handling CellClick event suppresses CellDoubleClick event.

Sri Guru Gauranga Jayate

In DataGridView, if one handles the CellClick event, CellDoubleClick event doesn't fire.

Om namo shridharaya.
Sri Guru Gauranga Jayate

DataGridView CellFormatting event is funny. As per the MSDN, the ConvertEventArgs argument has a property 'Value' that holds the unformatted value and must be set to the formatted (converted) value inside the event handler. But for DataGridViewCheckBoxColumn, this property had a fixed (constant) value irrespective of the underlying value of the DataGridView cell.

Om namo shridharaya

Wednesday, December 14, 2011

tableAdapter.Update method is 2-way

Sri Guru Gauranga Jayate

tableAdapter.Update method implies not just saving the dataset to the database but also retrieval of any autoincrement (identity) key values to the dataset after saving it to the database. In other words there's no need to call tableAdapter.Fill method to get the identity key values.

Om namo sridharaya.

Thursday, October 6, 2011

Mounting an ISO file in linux

mount -o loop disk1.iso /mnt/disk

Jaya Srila Prabhupada, Sathguru Bhagawan Sridhara Swamy Maharaja

Monday, May 16, 2011

What I learned yesterday...

Yesterday was Sri Narasimhadev's appearance day. A lot of obstacles got cleared!!

1. gimp - multiple layer editing. When a layer is pasted, it's in floating state; right click and say new layer.

2. Java - new BufferedReader(new FileReader("hari.txt")) - efficient read operation

3. when interviewing, check for behavioral aspects first. Behavioral aspects include things like team work, hunger to learn and resourcefulness. (we need people who can stay with us and not just run after money.)

4. jQuery - a good JavaScript library - decreases coding for all kinds of JavaScript tasks.

5. jQuery UI - another JavaScript library built on top of jQuery. Good for animations and interactive GUI

Saturday, April 16, 2011

Display UUID of disks in Debian

Jaya Srila Prabhupada.

The command is: blkid

Jaya Sri Sathguru Bhagawan Sridhara Swamy Maharaja

Wednesday, April 13, 2011

What I learned the last week

Jaya Srila Prabhupada (most merciful savior)

TCP/IP programming in Windows.

Started with my own classes ServerSocketFactory and ClientSocketFactory which encapsulated the TCP/IP api of .NET. One more class NetworkSocket encapsulated the Socket api of .NET

Learned by mistakes.

First mistake was that I bound the listening socket to the localhost (SockAddress.Local) instead of binding to SocketAddress.Any

I learnt that one can chain readers like this:
new StreamReader(new NetworkStream(new Socket(adr_family, sock_type, proto_type)));

Now writing or reading from a reader object writes to the underlying stream!

The client used to ask for something by sending a string of characters with a newline trailing and I was trying to receive it without expecting a newline. Sometimes it was the other way round. Both should settle on one scheme. When we call the 'ReadLine' method on a StreamReader, it doesn't return until it sees a newline. The ReadLine method always returns a string that was read from the stream (here socket).

What happens when you are trying to read from a connected socket but the remote socket is closed, the Receive method (analogous to 'recv' in unix socket programming) returns immediately with zero bytes. Analogously if we are using the 'ReadLine' method on a StreamReader of a socket, the ReadLine method returns immediately with a null value (and NOT a null string).

Jaya Sathguru Bhagawan Sri Sridhara Swamy maharaja.

Monday, March 28, 2011

Using 'du' command to leave out other filesystems

Jaya Srila Prabhupada.

du -hsx /home

this command leaves out other filesystems that may have been mounted in the filesystem heirarchy starting at /home.

Jaya Sathguru Bhagwan Sridhara Swamy Maharaja.

Backing up home folder

Jaya Srila Prabhupada

cp -vrx /home /home/ghd/mnt-backup

Because we use the -x option, this command doesn't copy contents from other filesystems that may have been mounted in the filesystem heirarchy starting from /home.

Jaya Sathguru Bhagwan Sridhara Swamy Maharaja.