Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6722125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:24:37+00:00 2026-05-26T09:24:37+00:00

I have the following function: private void populate() { String connectionString = Properties.Settings.Default.Database; String

  • 0

I have the following function:

private void populate()
    {
        String connectionString = Properties.Settings.Default.Database;

        String selectString = "select artikelnummer, omschrijving from Artikels";

        SqlDataReader reader = null;

        SqlConnection connection = new SqlConnection(connectionString);
        SqlCommand command = new SqlCommand(selectString);

        reader = command.ExecuteReader();
        connection.Open();
        int x = 0;
        while (reader.Read())
        {
            String item = String.Empty;
            item = Convert.ToString(reader["Artikelnummer"]) + "\t" + Convert.ToString(reader["Omschrijving"]);
            x++;
            listboxGeselecteerd.Items.Add(item);
        }            
    }

Everything that follows after reader = command.ExecuteReader(); is skipped.

Is there anything I’ve done wrong?

UPDATE: Moved the connection.Open(); to the right spot. Now, when I reach that line, my output shows Step into: Stepping over non-user code 'System.Data.SqlClient.SqlConnection.Open

And then skips the rest of the function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:24:38+00:00Added an answer on May 26, 2026 at 9:24 am

    My money is on a method higher up in the call stack eating the exception because this should’ve thrown one because the connection hadn’t been opened. That’s your biggest problem.

    The next problem you have is that your connection is not associated with the SqlCommand so even if it were opened, it wouldn’t matter.

    Finally, connection.Open(); needs to be before ExecuteReader.

    In addition to that, you really ought to be using using blocks.

    {
        String connectionString = Properties.Settings.Default.Database;
    
        String selectString = "select artikelnummer, omschrijving from Artikels";
    
        SqlDataReader reader = null;
    
        using (SqlConnection connection = new SqlConnection(connectionString))
        /* you also need to associate the connection with the command */
        using (SqlCommand command = new SqlCommand(selectString, connection))
        {
            connection.Open();
            reader = command.ExecuteReader();
            int x = 0;
            while (reader.Read())
            {
                String item = String.Empty;
                item = Convert.ToString(reader["Artikelnummer"]) + "\t" + Convert.ToString(reader["Omschrijving"]);
                x++;
                listboxGeselecteerd.Items.Add(item);
            }            
        }
    }
    

    How about some simple “printf”-style debugging and posting the exception you get?

    try
    {
       connection.Open();
       ... 
    }
    //catch (Exception e)
    catch (SqlException e)
    {
        // at least one of these..
        Console.WriteLine(e);
        MessageBox.Show(e);
        Debug.WriteLine(e);
    
        var inner = e.InnerException;
        while (inner != null)
        {
             //display / log / view
             inner = inner.InnerException;
        }
    }
    

    Given the exception text from the comments (A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll) looks more like the message you’d get just before the real message showed up, I would catch a SqlException and examine the InnerException(s).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simple function: private void EnableDisable941ScheduleBButton() { if (this._uosDepositorFrequency.Value != null)
I have the following serialization method: Private Function SerializeData(ByVal data As cData) As String
I have the following function: public void RestoreDatabase(String databaseName, String backUpFile, String serverName, String
I have the following function (that is incorrect): private void TreeView_DragDrop(object sender, DragEventArgs e)
I have created the following function for checking the connection status: private void checkConnectionStatus()
I have the following function: private static void prettyPrint(Document doc, File destFile) { TransformerFactory
If I have the following registry class: Class registry { private $_vars; public function
I have the following function that is pulling data from a database. The ajax
I have the following function void initBoard(int * board[BOARD_ROWS][BOARD_COLS]){ int z = 0; for(
I have an issue with the following code : class quicksort { private: void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.