DEV Community

Zachary Hadjah
Zachary Hadjah

Posted on

Debugging PostgreSQL while working with ASP.NET Core MVC applications

For our cohort, our instructors decided to use PostgreSQL to maintain the objects in the backend. PostgreSQL allows us to implement CICD principles by deploying the project to Heroku for free. Our CarPro project had us create a Parent table of type Lot and a child table of type Car. The website would display all the cars that the lot had for inventory. Our instructor Jason had a lot of experience troubleshooting PostgreSQL. Though I myself had issues, I decided to head to the breakout room and pay attention to what Jason was doing to help students troubleshoot their problems related to postgreSQL.

I exited the main zoom meeting and joined the breakout room that Jason and a few other students had started and decided to listen in on him trouble shooting with students. The very first problem most folks had was with their passwords, of course. Standard IT problems that will never go away. As someone that has 15 years of experience in the industry, He knew exactly how to fix it. Uninstall, then reinstall, and write down the password this time. Other problems occurred when it came to older versions of nuget packages being installed instead of the latest version.

The first set of complicated cases came when students were trying to use pgAdmin with their mvc applications but unknowingly had too many instances of pgAdmin downloaded. Students would try and work with the package manager console only to have their builds fail. Jason’s method of troubleshooting seemed very logical. He saw that the nuget package manager had installed npgsql. He then checked all the files inside the solution explorer that pertained to setting up pgAdmin. No problems were found inside any of the files. This was what led him to check all the installed programs on students laptop. Once you pull up the Apps & Features option you will be able to see how many versions of the software the student has installed. Some students had too many versions of postgreSQL installed onto the computer. This caused conflicts because EntityFrameworkCore didn’t know exactly which one to interact with, which was why there were so many build errors.

Windows Key> Type: installed > Apps & Features > Type: postgresql

Alt Text

One of the harder to spot problems when it came to troubleshooting postgreSQL issues was with the connection strings. Under no circumstance will an application run as intended if the connection string is not properly written. Below is my connection string for the Car Pro project.

Alt Text

From Server all the way down to Password, all the parameters are correct. However, when I was inside listening in on Jason troubleshoot with some of the other students, I had heard him give students some insight into how pgAdmin configures connections strings. Multiple students had issues working with the package manager because they had conflicting port numbers. The default port connection that PostgreSQL uses is 5432. Students had all sorts of numbers in their ports. To fix the port number issues, me and a few other students found answers on stack overflow as to how to find the correct port number, or how to change it. Had I not stayed in that breakout room, I wouldn’t have had that piece of knowledge.

As written in a few of my other articles, I’ve become a lot better at the art of asking Questions to developers. When troubleshooting with senior developer that have years of experience on you, always analyze their language. When troubleshooting out loud amongst each other, seniors will often times think out loud aswell. Keep their words at the back of your mind so that if the problem is fixed, you can ask them about their thought process later on. Also, analyze their toolkits and the software they use in order to help them troubleshoot. Instead of just waiting my turn in order to get any issues I had fixed, I paid close attention to Jason’s thought process when talking to other students. I also asked him about how he was able to come up with certain solutions.

He told me that I should always try to focus on the problem, and then isolate it completely. After that, think of how the broken mechanism gets triggered/activated. To properly do this, reading documentation is key. If you have seen that the files inside the solution explorer are all properly configured, but when _context is called to store data into the Database and the program crashes, you can then infer that either the problem lies in how the database was called, or that the database was never called in the first place. At this point, you’d go back into the appropriate files in the solution explorer and check. After checking and seeing that the DB was called correctly, you infer that the software for the DB hasn’t been called. This leads the developer to bring up the installed programs. This is where you would be able to tell that pgAdmin has been downloaded multiple times. With multiple versions, the program doesn’t know which to use, which is why the package manager is giving error messages. More on how to extract info from senior developers will be coming in other articles.

Top comments (0)