Solved

VB, Teradata

Posted on 2011-02-22
4
730 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:DoukAli
4 Comments
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
Comment Utility
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
 
LVL 14

Expert Comment

by:Brook Braswell
Comment Utility
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
 

Author Comment

by:DoukAli
Comment Utility
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
 
LVL 50

Expert Comment

by:Lowfatspread
Comment Utility
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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

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

11 Experts available now in Live!

Get 1:1 Help Now