Solved

loop to get data from sql

Posted on 2003-11-19
9
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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
 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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