Solved

loop to get data from sql

Posted on 2003-11-19
9
302 Views
Last Modified: 2010-04-16
Hi,
I want to have function will wait for the row has been release from SQL. It is still lock then I need to have loop to check every 10 seconds with through exception.
Thanks!
jpc
0
Comment
Question by:jpchen
  • 5
  • 4
9 Comments
 
LVL 7

Accepted Solution

by:
jj819430 earned 125 total points
Comment Utility
public SqlDataAdapter Connection(string SqlStatement)
            {
                  SqlConnection myConnection = new SqlConnection("server=(local);uid=****;pwd=*****;database=DatabaseName;");
                  SqlDataAdapter myCommand = new SqlDataAdapter(SqlStatement, myConnection);
                  return myCommand;
}
// Connection takes in a string that is what you are searching for

public int SqlRowCheck(string SqlQuestion)
            {
                  SqlConnection myConnection = new SqlConnection("");
                  SqlDataAdapter myCommand = new SqlDataAdapter(SqlQuestion,myConnection);
                  DataSet Check = new DataSet();
                  myCommand.Fill(Check,"TABLE NAME");
                  return Convert.ToInt32(Check.Tables["TABLE NAME"].Rows[0][0]);
            }

// this assumes that you are locking with just an int value on the table. Without a better knowledge of how your design is set I can't get a more specific answer

in a function call this.

int Locked = 1;
while(locked != 0)
{
locked = SqlRowCheck(YourSearchString)
// delay can be done if you want.
}

SqlDataAdapter Connection(string SqlStatement);
0
 

Author Comment

by:jpchen
Comment Utility
if I setting up the timeout in the connection string, how to handle the time out issue?
0
 
LVL 7

Expert Comment

by:jj819430
Comment Utility
http://www.codeproject.com/csharp/timeralarm.asp

This link can show you how to build a solid timer
0
 

Author Comment

by:jpchen
Comment Utility
I don't want to use other timer, I rember there is timeout value you can add to the connection string, but how to handle the timeout issue, there is what i am not sure what to do it.
Thanks!
jpc
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Expert Comment

by:jj819430
Comment Utility
to set the timeout on the connection string
myConnection.ConnectionTimeout = TheAmountOfTime;
0
 
LVL 7

Expert Comment

by:jj819430
Comment Utility
0
 

Author Comment

by:jpchen
Comment Utility
thanks, but how to handle after timout?
0
 
LVL 7

Expert Comment

by:jj819430
Comment Utility
SqlException is what I think it throws.

so do this.
try{

blah blah blah

}
catch(SqlException error)

then you can catch and handle the exception right there. Your app will know it failed. if it fails have it loop.
0
 

Author Comment

by:jpchen
Comment Utility
Thanks,  but how can I just catch the timeout error, I don't want to loop with other SQL issue.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
c# string 6 38
c#.net application + check if already running 5 48
Build JSON from table records 17 38
Pass through dll 2 32
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now