We help IT Professionals succeed at work.

VB.NET application not halting with an error message

Last Modified: 2019-01-23
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?
Watch Question

Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Do you have error handling implemented in that section of code (i.e. a Try-Catch statement)?


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 (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

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?


"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)
                    cmd.CommandText = "Select ReturnId, [DateCode] + '-' + [SerialNo] As SN, " &
                    "WorkOrderId From Returns"
                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 VermaakSenior Consultant
Awarded 2017
Distinguished Expert 2019

Are you actually calling Returns_Load()?
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

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?


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.
Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014
This one is on us!
(Get your first solution completely free - no credit card required)


Thanks.  I use MZ tools for Access.  I didn't know it was available for VB.net.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.