VB, Teradata

Hello,

Need to query a Teradata Table and if the record exist return code 0 if not sleep for 5 min and try again until record found. Preferably in VB.Net or VBS. Thanks
DoukAliAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robberbaron (robr)Commented:
i assume you have a ODBC driver installed for Teradata. ?

see http://www.connectionstrings.com/teradata

try this code..... written from scratch and not tested for syntax.




Dim objConnection
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString =
      "Provider=Teradata;DBCName=MyDbcName;Database=myDataBase; Uid=myUsername;Pwd=myPassword;"
objConnection.ConnectionTimeout = 0
objConnection.Open

Set rs = CreateObject("ADODB.recordset")
strSQL = "SELECT * FROM myTable"

maxcount = 10  'dont allow an infinite loop
count=0 : ok = false
do while count<maxcount and ok=false
     rs.open strSQL, objConnection , 3,3
     if rs.eof then
         'no records so wait
         count=count+1
         rs.close
         xx = timer
         do while timer < xx + 6000 * 5  'waite 5minutes
             do events
         loop
       else
          'records returned
          ok =true
     end if
loop
    
if ok then 
   'work on records
 else
   wscript.echo "gave up waiting after " & maxcount & " tries"
end if

rs.Close
Set rs = Nothing

objConnection.Close
Set objConnection= Nothing

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brook BraswellApplication Development ManagerCommented:
The query should be structured the same for any size database
if your dataset returns 0 records then sleep.
but because you are looking at such a large table I would have to ask...

What does the query look like?  - perhaps your problem is in getting a fast response.


sql = "SELECT DATA FROM YOURTABLE WHERE CONDITION = TRUE"
DIM DR AS DATAROW
DIM SQLCMD AS NEW OLEDB.OLEDBCOMMAND(SQL,OPENSQLCONN)
DIM SQLDS AS NEW DATASET
DIM SQLDA AS NEW OLEDB.OLEDBDATAADAPTER(SQLCMD)
SQLDA.FILL(SQLDS)
IF SQLDS.TABLES(0).ROWS.COUNT = 0 THEN
'   SLEEP PROCESS
ELSE
  ' DO YOUR KEWL THING HERE
END IF
0
DoukAliAuthor Commented:
The table I'm querying is very small (about 10 records). I'm running some processes and whenever one finishes it would write to a table by updating the value of a column to 1. What I need to do is have this vb code check the table for that value and either return a code ... or just write 'done' in a txt file.

Thanks for your help.
0
LowfatspreadCommented:
main thing to  remember then is to make sure that the sql code runs in its own transactionn
so that you don't cause contention locks...

begin tran
select x...
commit tran
test
   sleep
else
   do something
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.