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 8724051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:45:04+00:00 2026-06-13T07:45:04+00:00

I have a Winforms application that executes a stored procedure which examines several rows

  • 0

I have a Winforms application that executes a stored procedure which examines several rows (around 500k). In order to inform the user about how many rows have already been processed, I would need a stored procedure which returns a value every n rows. For example, every 1000 rows processed (most are INSERT).

Otherwise I would be able only to inform when ALL rows are processed. Any hints how to solve this?

I thought it could be useful to use a trigger or some scheduled task, but I cannot figure out how to implement it.

  • 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-06-13T07:45:05+00:00Added an answer on June 13, 2026 at 7:45 am

    So this is very interesting question. I’ve tried it about 5 years ago with no success, so this is a little challenge for me 🙂 Well, here’s is what I’ve got for you.

    To send message from SQL Server you need to use raiserror command with nowait option. So I’ve wrote a stored procedure

    create procedure sp_test
    as
    begin
        declare @i bigint, @m nvarchar(max)
    
         select @i = 1
    
         while @i < 10
         begin
             waitfor delay '00:00:01'
             select @m = cast(@i as nvarchar(max))
             raiserror(@m, 0, 0) with nowait
             select @i = @i + 1
         end
    end
    

    If you try to execute it in SSMS, you’ll see that message appearing in message section while procedure still works. Ok, we got messages from server. Now we need to process it on the client.

    To do that, I’ve created a SQLCommand like this

    SqlCommand cmd = new SqlCommand("sp_Test");
    cmd.Connection = new SqlConnection("Server=HOME;Database=Test;Trusted_Connection=True;");
    

    now to catch a messages we using InfoMessage of SqlConnection object:

    cmd.Connection.InfoMessage += Connection_InfoMessage;
    
    static void Connection_InfoMessage(object sender, SqlInfoMessageEventArgs e)
    {
        Console.WriteLine(e.Message);
    }
    

    And now we’re trying to display messages

    cmd.Connection.Open();
    try
    {
        SqlDataReader r = cmd.ExecuteReader();
    }
    finally
    {
        cmd.Connection.Close();
    }
    

    SUCCESS 🙂

    BTW, you cannot use ExecuteNonQuery(), because it returns concatenated messages at the end of execution.
    Also, you may want to run your query in background mode, so it will not lock you winform client.

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

Sidebar

Related Questions

I have a WinForms application that requires some configuration which I do at install
I have a winforms application that populates an scrollable area with several UserControls. My
I have a Winforms application that generates its own PrintDocument object for printing. It
We have a WinForms application that uses SQL server to store its data. To
I have a Winforms application that schedules some work using a service. The service
I have a Winforms application that dynamically instantiates external form objects for use in
I have a WinForms application that makes use of a TaskDialog library that leverages
I just started to use SQL Server 2008. I have a winforms application that
I have a winforms Application, On Close button click, I am hiding that application
I have a WinForms application (WF), and a Library called by that WinForms application

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.