L
Lee Moore
I am trying to develop a threaded function to create a dataset from an
Oracle database. When querying an elaborate view, queries take a while. I
would like to place and animated wait dialog up while the query runs. I
don't know much about threading, so bear with me. The following code
contains a class that works fine when threading is not used, but fails to
return a dataset when I execute the threading code. Any help would be
appreciated.
Public Class QueryClass
Public QueryString As String
Public DSet As DataSet
Public TblName As String
Public Sub GetOracleDataset()
SyncLock GetType(QueryClass)
Dim connectionString As String =
"Provider=OraOLEDB.Oracle;Data Source=PRODUCTION;User
Id=myuser;Password=abc123;"
Dim dbConnection As New
System.Data.OleDb.OleDbConnection(connectionString)
Dim dbCommand As New System.Data.OleDb.OleDbCommand
Dim dataSet As New System.Data.DataSet(TblName)
Dim dataAdapter As New System.Data.OleDb.OleDbDataAdapter
DSet = New DataSet
Try
dbCommand.CommandText = QueryString
dbCommand.Connection = dbConnection
dataAdapter.SelectCommand = dbCommand
dataAdapter.Fill(DSet, TblName)
Catch e As Exception
Dim logfile As New
System.IO.StreamWriter("c:\oracle.log")
logfile.WriteLine(e.Message & Chr(13) & "SQL: " &
QueryString)
logfile.Close()
MsgBox(e.Message & Chr(13) & "SQL: " & QueryString)
DSet = Nothing
Exit Sub
End Try
End SyncLock
End Sub
End Class
Sub DoThis()
Dim WaitForm As New dlgWait
WaitForm.Show()
WaitForm.Refresh()
Dim Qry As New QueryClass
Dim t As System.Threading.Thread
t = New Threading.Thread(AddressOf Qry.GetOracleDataset)
t.Priority = Threading.ThreadPriority.Highest
Qry.QueryString = TextBox1.Text
Qry.TblName = "tbl"
t.Start()
If IsNothing(Qry.DSet) Then
MsgBox("No Dataset")
Exit Sub
End If
DataGrid1.DataSource = Qry.DSet.Tables(Qry.TblName)
WaitForm.Close()
End Sub
Oracle database. When querying an elaborate view, queries take a while. I
would like to place and animated wait dialog up while the query runs. I
don't know much about threading, so bear with me. The following code
contains a class that works fine when threading is not used, but fails to
return a dataset when I execute the threading code. Any help would be
appreciated.
Public Class QueryClass
Public QueryString As String
Public DSet As DataSet
Public TblName As String
Public Sub GetOracleDataset()
SyncLock GetType(QueryClass)
Dim connectionString As String =
"Provider=OraOLEDB.Oracle;Data Source=PRODUCTION;User
Id=myuser;Password=abc123;"
Dim dbConnection As New
System.Data.OleDb.OleDbConnection(connectionString)
Dim dbCommand As New System.Data.OleDb.OleDbCommand
Dim dataSet As New System.Data.DataSet(TblName)
Dim dataAdapter As New System.Data.OleDb.OleDbDataAdapter
DSet = New DataSet
Try
dbCommand.CommandText = QueryString
dbCommand.Connection = dbConnection
dataAdapter.SelectCommand = dbCommand
dataAdapter.Fill(DSet, TblName)
Catch e As Exception
Dim logfile As New
System.IO.StreamWriter("c:\oracle.log")
logfile.WriteLine(e.Message & Chr(13) & "SQL: " &
QueryString)
logfile.Close()
MsgBox(e.Message & Chr(13) & "SQL: " & QueryString)
DSet = Nothing
Exit Sub
End Try
End SyncLock
End Sub
End Class
Sub DoThis()
Dim WaitForm As New dlgWait
WaitForm.Show()
WaitForm.Refresh()
Dim Qry As New QueryClass
Dim t As System.Threading.Thread
t = New Threading.Thread(AddressOf Qry.GetOracleDataset)
t.Priority = Threading.ThreadPriority.Highest
Qry.QueryString = TextBox1.Text
Qry.TblName = "tbl"
t.Start()
If IsNothing(Qry.DSet) Then
MsgBox("No Dataset")
Exit Sub
End If
DataGrid1.DataSource = Qry.DSet.Tables(Qry.TblName)
WaitForm.Close()
End Sub