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 4 1594
What is the nature of the exception?
--
Get a powerful web, database, application, and email hosting with KJM
Solutions http://www.kjmsolutions.com
"Lee Moore" <le******@hotmail.com> wrote in message
news:O3**************@TK2MSFTNGP03.phx.gbl... 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
No exception, the process just never starts and the value of the dataset
property of the class is null. Remove the threading, and everything works
fine. I'm lost
"vbnetdev" <vb******@community.nospam> wrote in message
news:uc**************@TK2MSFTNGP05.phx.gbl... What is the nature of the exception?
-- Get a powerful web, database, application, and email hosting with KJM Solutions http://www.kjmsolutions.com "Lee Moore" <le******@hotmail.com> wrote in message news:O3**************@TK2MSFTNGP03.phx.gbl...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
Lee,
I suspect what's happening is the read immediately after calling
Thread.Start is seeing that Qry.DSet is nothing because the thread
hasn't set it yet.
If you're using .NET 2.0 then you might find BackgroundWorker class
helpful. It simplifies of the task of executing code asynchronously.
Brian
Lee Moore wrote: 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
For a start, take out the MessageBox statements when running on a background
thread. Use tracing or progress events.
"Lee Moore" <le******@hotmail.com> wrote in message
news:On**************@TK2MSFTNGP05.phx.gbl... No exception, the process just never starts and the value of the dataset property of the class is null. Remove the threading, and everything works fine. I'm lost
"vbnetdev" <vb******@community.nospam> wrote in message news:uc**************@TK2MSFTNGP05.phx.gbl... What is the nature of the exception?
-- Get a powerful web, database, application, and email hosting with KJM Solutions http://www.kjmsolutions.com "Lee Moore" <le******@hotmail.com> wrote in message news:O3**************@TK2MSFTNGP03.phx.gbl...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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Elliot Rodriguez |
last post by:
Hi:
I am writing a WinForm app that contains a DataGrid control and a StatusBar
control. My goal is to update the status bar using events from a separate
class, as well as some other simple...
|
by: Eric Sabine |
last post by:
OK, I'm trying to further my understanding of threading. The code below I
wrote as kind of a primer to myself and maybe a template that I could use in
the future. What I tried to do was pass data...
|
by: KC |
last post by:
Hey,
I'm trying to implement a cancel button in my app (this is after the bulk of
the program has been built). To do this I, of course, need to use a thread
to run the time consuming method...
|
by: Phil G. |
last post by:
I was recently struggling to adapt an example I have using delegate methods,
IasynResult and AsynCallback.
Doing a little research I came across an example, which in fact was being
used to...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |