1
votes

After much effort getting my MVC5 vb.net app configured with Npgsql and EntityFramework6.Npgsql I can connect to the postgres database fine using the Entity Data Model Wizard in Visual Studio 2017, creating a new connection with Data Provider of PostgreSQL Database, entering my database server details and testing the connection (succeeds). I can also double-click the EDMX file and add tables, etc as expected. This is my first project that talks to a postgreSQL database (normally use MS SQL Server). Everything seems to be happy and fine until I encounter code that is a linq statement that attempts to query the database. My Linq statement is:

    Dim l_ListOfPwrCycleCrashEvents As List(Of pwr_cycle_crash_events) = (From item In m_AnalyticsEntities.pwr_cycle_crash_events Where item.serialnumber = "0123445678" Select item).ToList

I have the statement in a try/catch block, but visual studio still reports the following:

Exception thrown:'System.Net.Sockets.SocketException' in System.dll Additional information: A non-blocking socket operation could not be completed immediately occurred

I cannot seem to figure out why this statement fails. I am able to use similar statements against a different EntityFramework (MS SQL Server) that is also configured in the application.

The complete method that contains the linq statement:

    Public ReadOnly Property iCountOfPwrCycleCrashEvents(
                ByVal a_sSerialNumber As String
            ) As Integer Implements IAnalytics.iCountOfPwrCycleCrashEvents
                Get
                    Try
                        Dim l_ListOfPwrCycleCrashEvents As List(Of pwr_cycle_crash_events) = (From item In m_AnalyticsEntities.pwr_cycle_crash_events
                                                                                              Where item.serialnumber = a_sSerialNumber
                                                                                              Select item).ToList
                        If (l_ListOfPwrCycleCrashEvents IsNot Nothing) Then Return l_ListOfPwrCycleCrashEvents.Count
                    Catch l_Exception2 As System.Net.Sockets.SocketException
                        Dim askjfhakjh As Integer = 7
                    Catch l_Exception As Exception
                        Dim kjhadkjh As Integer = 1
                    End Try
                    Return 0
                End Get
            End Property

I am using Npgsql v4.1.1 and EntityFramework6.Npgsql v6.3.0 in an application that targets .NET Framework 4.5.1.

I can't seem to figure out why the linq statement throws this exception or how to solve the problem. What suggestions do you have?

1

1 Answers

0
votes

I figured out the issue. I was using 4.5.1 framework because I thought I had a dependency that would not allow me to move to 4.5.2. I went to Package Manager Console and ran the following command: Update-Package -ProjectName myProjectName -reinstall By doing so, I found that I had a package that was needed but could not be loaded because it required the 4.5.2 framework (or higher). I changed the framework of the app to 4.5.2 and issued the above Package Manager command and it executed without errors. I ran the app and the linq statement no longer throws an exception.