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