Solved

loop to get data from sql

Posted on 2003-11-19
9
306 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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