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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:23:47+00:00 2026-05-23T02:23:47+00:00

Please help me find the defect in my logic. I have two variables named

  • 0

Please help me find the defect in my logic. I have two variables named “prev” and “next”…What i am basically doing is reading the data from my database every 5s and printing it out using Websync server if next and prev are NOT equal. I have two rows in my database . It looks like

ID
8
10

Here is the link to the code http://pastebin.com/Hb3eH2Qv

When i run my program, i get the result as

8 10 8 10
8 10
8 10 8 10
8 10

….. (so on)

But, the result should be just

8 10

I dont know how 8 10 8 10 appears. Data gets concatenated twice.

NOTE: You can just see the code in PublishLoop() function

private void PublishLoop()
        {
            String prev=String.Copy("");
            String next=String.Copy("");
            String ConnectionString = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString();
            SqlConnection connection = new SqlConnection(ConnectionString);
            SqlCommand command = connection.CreateCommand();
            command.CommandText = "select ID from Tab1";
            command.Notification = null;

            while (Running)
            {
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    StreamWriter sw1 = new StreamWriter("C:\\Users\\Thothathri\\Desktop\\next.txt");
                    while ((reader.Read()))
                    {
                        //Response.Write(reader[0].ToString());
                        next = String.Concat(next,reader[0].ToString());
                        sw1.WriteLine(next);

                    }
                    sw1.Close();


                    if (!prev.Equals(next))
                    {
                        Publisher publisher = new Publisher(new PublisherArgs
                        {
                            DomainKey = "c80cb405-eb77-4574-9405-5ba51832f5e6",
                            DomainName="localhost"
                        });
                        Publication publication = publisher.Publish("/test", JSON.Serialize(next));
                        if (publication.Successful == true)
                        {
                            StreamWriter sw = new StreamWriter("C:\\Users\\Thothathri\\Desktop\\error123.txt");
                            sw.WriteLine("success");
                            sw.WriteLine(next);
                            sw.Close();
                        }
                        else
                        {
                            StreamWriter sw = new StreamWriter("C:\\Users\\Thothathri\\Desktop\\error123.txt");
                            sw.Write("failed");
                            sw.Close();
                        }
                        prev = String.Copy(next);
                        next = String.Copy("");
                    }


                }
                Thread.Sleep(5000);

            }
        }
  • 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-23T02:23:48+00:00Added an answer on May 23, 2026 at 2:23 am

    Renuiz answered it in a comment, but it is because you’re not clearing next.

    So you build the string “8 10” in next, store it in prev. Next time you concat “8 10” with next, making “8 10 8 10”. Which is different so you print it.

                    if (!prev.Equals(next))
                    {
     ....
                        prev = String.Copy(next);
                        next = String.Copy("");
                    }
    

    This is the end of that loop. You should really be clearing next at the beginning of that loop.

    Also you can just set the string

    next = String.Empty;
    

    I would declare next inside your while loop, as you don’t need it in the greater scope, and I would call it current rather than next.

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

Sidebar

Related Questions

Please help me to find out error in my SQL query. I have created
Please help me find a regular expression to parse the data like this: 'EBB112'
Could you please help me find out the time complexity of the Fleury' algorithm
ereg and eregi functions will be deleted from Php. Please help to find alternatives
I cannot find where the sqlcmd is? i just want the prompt. please help!
Please help! Background info I have a WPF application which accesses a SQL Server
Can someone please help me find a list of flags that are needed by
the following regexp is wrong - can someone please help to find all :-)
I'm newbie to silverlight. Please help me find setting page title. See I don't
Can someone please help me find if there is any option selected I currently

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.