VB.NET application not halting with an error message

In Visual Studio Professional 2015, if there's an runtime error in the form load event of a vb.net application, the form continues to open without running the rest of the code, and I don't see a report of any error in either the immediate window or the error list window.  I tested this by purposefully setting a connection object with an incorrect connection string.  How can I get the program to halt and give me an error message instead of skipping the rest of the code and opening the form?
LVL 1
Declan_BasileITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Do you have error handling implemented in that section of code (i.e. a Try-Catch statement)?
Declan_BasileITAuthor Commented:
No.  Not yet.  I was hoping to get it to stop execution and give me an error message  whenever there's an exception and there's no error handling code,  like what happens when I'm programming in VBA.  Is there a way to configure it to work that way?
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Generally speaking you should get an error message, depending on the severity of the error. I don't know if there's any configuration needed - at least, I've never really had to configure it. It's just worked that way (but I don't always get an error, even when I think I should).

Are you working in DEBUG configuration?

Can you show the code that you're expecting to error out?
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Declan_BasileITAuthor Commented:
"Debug" is selected from the drop down that has "Release" and "Configuration Manager" as other options.  I'm just clicking "Start" to run the program.  I purposely made the connection string "strConn" incorrect, and the program didn't execute the rest of the code but still opened the form and didn't give me an error.  Also, I unintentionally enclosed the rowfilter value in single quotes instead of double quotes (vwRt.RowFilter = 'WorkOrderId = 52073') and again the program didn't execute the rest of the lines of code beyond that but opened the form without an error message.

    Private Sub Returns_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim dtWO As New DataTable
        Dim dtRt As New DataTable

        Using cn As New SqlConnection(strConn)
            Using cmd As New SqlCommand("Select WorkOrderId, [Number] FROM WorkOrders Where " &
            "[Number] like '%?' or [Number] like '%R' Order By NumberSort DESC", cn)
                Using da As New SqlDataAdapter(cmd)
                    cn.Open()
                    da.Fill(dtWO)
                    cmd.CommandText = "Select ReturnId, [DateCode] + '-' + [SerialNo] As SN, " &
                    "WorkOrderId From Returns"
                    da.Fill(dtRt)
                End Using
            End Using
        End Using
        cbxWorkOrderId.ValueMember = "WorkOrderId"
        cbxWorkOrderId.DisplayMember = "Number"
        cbxWorkOrderId.DataSource = dtWO
        cbxWorkOrderId.SelectedIndex = -1

        cbxReturnId.ValueMember = "cbxReturnId"
        cbxReturnId.DisplayMember = "SN"
        vwRt = New DataView(dtRt)
        vwRt.RowFilter = "WorkOrderId = 52073"
        cbxReturnId.DataSource = vwRt
        cbxReturnId.SelectedIndex = -1

    End Sub

Open in new window

Shaun VermaakTechnical SpecialistCommented:
Are you actually calling Returns_Load()?
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
If you put a breakpoint in, does the debugger stop at the breakpoint?

If a connection string is invalid, then the debugger should throw an error when the connection is opened. If that's not happening, then I'd suspect something wrong with your installation of VS (or Windows).

I'd be curious what would happen if you implement a Try - Catch. Does the error handler also miss that error?
Declan_BasileITAuthor Commented:
Sorry for the late response.  I was busy with another post for another problem and I didn't realize you had responded.  When I put in a breakpoint the program hangs for about 30 seconds trying to open a connection to an instance of SQL Server that doesn't exist, then skips the rest of the lines of code and opens the form without throwing any errors.  Using try/catch, however, does throw an exception.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I'm not sure why it would do that - not throw an error when it can't open a connection - but the simple fix is to add error handling. I use MZTools, which can add your custom error handler easily.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Declan_BasileITAuthor Commented:
Thanks.  I use MZ tools for Access.  I didn't know it was available for VB.net.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.