Solved

loop to get data from sql

Posted on 2003-11-19
9
305 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
ID: 9787814
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
ID: 9788372
if I setting up the timeout in the connection string, how to handle the time out issue?
0
 
LVL 7

Expert Comment

by:jj819430
ID: 9788430
http://www.codeproject.com/csharp/timeralarm.asp

This link can show you how to build a solid timer
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:jpchen
ID: 9788489
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
 
LVL 7

Expert Comment

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

Expert Comment

by:jj819430
ID: 9788549
0
 

Author Comment

by:jpchen
ID: 9788610
thanks, but how to handle after timout?
0
 
LVL 7

Expert Comment

by:jj819430
ID: 9788645
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
ID: 9792094
Thanks,  but how can I just catch the timeout error, I don't want to loop with other SQL issue.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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