473,626 Members | 3,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threading a Create Dataset method

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 GetOracleDatase t()
SyncLock GetType(QueryCl ass)
Dim connectionStrin g As String =
"Provider=OraOL EDB.Oracle;Data Source=PRODUCTI ON;User
Id=myuser;Passw ord=abc123;"
Dim dbConnection As New
System.Data.Ole Db.OleDbConnect ion(connectionS tring)
Dim dbCommand As New System.Data.Ole Db.OleDbCommand
Dim dataSet As New System.Data.Dat aSet(TblName)
Dim dataAdapter As New System.Data.Ole Db.OleDbDataAda pter
DSet = New DataSet
Try
dbCommand.Comma ndText = QueryString
dbCommand.Conne ction = dbConnection
dataAdapter.Sel ectCommand = dbCommand
dataAdapter.Fil l(DSet, TblName)
Catch e As Exception
Dim logfile As New
System.IO.Strea mWriter("c:\ora cle.log")
logfile.WriteLi ne(e.Message & Chr(13) & "SQL: " &
QueryString)
logfile.Close()
MsgBox(e.Messag e & 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.Refres h()

Dim Qry As New QueryClass
Dim t As System.Threadin g.Thread
t = New Threading.Threa d(AddressOf Qry.GetOracleDa taset)
t.Priority = Threading.Threa dPriority.Highe st

Qry.QueryString = TextBox1.Text
Qry.TblName = "tbl"

t.Start()

If IsNothing(Qry.D Set) Then
MsgBox("No Dataset")
Exit Sub
End If

DataGrid1.DataS ource = Qry.DSet.Tables (Qry.TblName)
WaitForm.Close( )

End Sub

Apr 14 '06 #1
4 1605
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******@hotma il.com> wrote in message
news:O3******** ******@TK2MSFTN GP03.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 GetOracleDatase t()
SyncLock GetType(QueryCl ass)
Dim connectionStrin g As String =
"Provider=OraOL EDB.Oracle;Data Source=PRODUCTI ON;User
Id=myuser;Passw ord=abc123;"
Dim dbConnection As New
System.Data.Ole Db.OleDbConnect ion(connectionS tring)
Dim dbCommand As New System.Data.Ole Db.OleDbCommand
Dim dataSet As New System.Data.Dat aSet(TblName)
Dim dataAdapter As New System.Data.Ole Db.OleDbDataAda pter
DSet = New DataSet
Try
dbCommand.Comma ndText = QueryString
dbCommand.Conne ction = dbConnection
dataAdapter.Sel ectCommand = dbCommand
dataAdapter.Fil l(DSet, TblName)
Catch e As Exception
Dim logfile As New
System.IO.Strea mWriter("c:\ora cle.log")
logfile.WriteLi ne(e.Message & Chr(13) & "SQL: " &
QueryString)
logfile.Close()
MsgBox(e.Messag e & 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.Refres h()

Dim Qry As New QueryClass
Dim t As System.Threadin g.Thread
t = New Threading.Threa d(AddressOf Qry.GetOracleDa taset)
t.Priority = Threading.Threa dPriority.Highe st

Qry.QueryString = TextBox1.Text
Qry.TblName = "tbl"

t.Start()

If IsNothing(Qry.D Set) Then
MsgBox("No Dataset")
Exit Sub
End If

DataGrid1.DataS ource = Qry.DSet.Tables (Qry.TblName)
WaitForm.Close( )

End Sub

Apr 14 '06 #2
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******@commu nity.nospam> wrote in message
news:uc******** ******@TK2MSFTN GP05.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******@hotma il.com> wrote in message
news:O3******** ******@TK2MSFTN GP03.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 GetOracleDatase t()
SyncLock GetType(QueryCl ass)
Dim connectionStrin g As String =
"Provider=OraOL EDB.Oracle;Data Source=PRODUCTI ON;User
Id=myuser;Passw ord=abc123;"
Dim dbConnection As New
System.Data.Ole Db.OleDbConnect ion(connectionS tring)
Dim dbCommand As New System.Data.Ole Db.OleDbCommand
Dim dataSet As New System.Data.Dat aSet(TblName)
Dim dataAdapter As New System.Data.Ole Db.OleDbDataAda pter
DSet = New DataSet
Try
dbCommand.Comma ndText = QueryString
dbCommand.Conne ction = dbConnection
dataAdapter.Sel ectCommand = dbCommand
dataAdapter.Fil l(DSet, TblName)
Catch e As Exception
Dim logfile As New
System.IO.Strea mWriter("c:\ora cle.log")
logfile.WriteLi ne(e.Message & Chr(13) & "SQL: " &
QueryString)
logfile.Close()
MsgBox(e.Messag e & 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.Refres h()

Dim Qry As New QueryClass
Dim t As System.Threadin g.Thread
t = New Threading.Threa d(AddressOf Qry.GetOracleDa taset)
t.Priority = Threading.Threa dPriority.Highe st

Qry.QueryString = TextBox1.Text
Qry.TblName = "tbl"

t.Start()

If IsNothing(Qry.D Set) Then
MsgBox("No Dataset")
Exit Sub
End If

DataGrid1.DataS ource = Qry.DSet.Tables (Qry.TblName)
WaitForm.Close( )

End Sub


Apr 17 '06 #3
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 BackgroundWorke r 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 GetOracleDatase t()
SyncLock GetType(QueryCl ass)
Dim connectionStrin g As String =
"Provider=OraOL EDB.Oracle;Data Source=PRODUCTI ON;User
Id=myuser;Passw ord=abc123;"
Dim dbConnection As New
System.Data.Ole Db.OleDbConnect ion(connectionS tring)
Dim dbCommand As New System.Data.Ole Db.OleDbCommand
Dim dataSet As New System.Data.Dat aSet(TblName)
Dim dataAdapter As New System.Data.Ole Db.OleDbDataAda pter
DSet = New DataSet
Try
dbCommand.Comma ndText = QueryString
dbCommand.Conne ction = dbConnection
dataAdapter.Sel ectCommand = dbCommand
dataAdapter.Fil l(DSet, TblName)
Catch e As Exception
Dim logfile As New
System.IO.Strea mWriter("c:\ora cle.log")
logfile.WriteLi ne(e.Message & Chr(13) & "SQL: " &
QueryString)
logfile.Close()
MsgBox(e.Messag e & 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.Refres h()

Dim Qry As New QueryClass
Dim t As System.Threadin g.Thread
t = New Threading.Threa d(AddressOf Qry.GetOracleDa taset)
t.Priority = Threading.Threa dPriority.Highe st

Qry.QueryString = TextBox1.Text
Qry.TblName = "tbl"

t.Start()

If IsNothing(Qry.D Set) Then
MsgBox("No Dataset")
Exit Sub
End If

DataGrid1.DataS ource = Qry.DSet.Tables (Qry.TblName)
WaitForm.Close( )

End Sub


Apr 17 '06 #4
For a start, take out the MessageBox statements when running on a background
thread. Use tracing or progress events.
"Lee Moore" <le******@hotma il.com> wrote in message
news:On******** ******@TK2MSFTN GP05.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******@commu nity.nospam> wrote in message
news:uc******** ******@TK2MSFTN GP05.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******@hotma il.com> wrote in message
news:O3******** ******@TK2MSFTN GP03.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
appreciate d.

Public Class QueryClass
Public QueryString As String
Public DSet As DataSet
Public TblName As String

Public Sub GetOracleDatase t()
SyncLock GetType(QueryCl ass)
Dim connectionStrin g As String =
"Provider=OraOL EDB.Oracle;Data Source=PRODUCTI ON;User
Id=myuser;Passw ord=abc123;"
Dim dbConnection As New
System.Data.Ole Db.OleDbConnect ion(connectionS tring)
Dim dbCommand As New System.Data.Ole Db.OleDbCommand
Dim dataSet As New System.Data.Dat aSet(TblName)
Dim dataAdapter As New System.Data.Ole Db.OleDbDataAda pter
DSet = New DataSet
Try
dbCommand.Comma ndText = QueryString
dbCommand.Conne ction = dbConnection
dataAdapter.Sel ectCommand = dbCommand
dataAdapter.Fil l(DSet, TblName)
Catch e As Exception
Dim logfile As New
System.IO.Strea mWriter("c:\ora cle.log")
logfile.WriteLi ne(e.Message & Chr(13) & "SQL: " &
QueryString)
logfile.Close()
MsgBox(e.Messag e & 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.Refres h()

Dim Qry As New QueryClass
Dim t As System.Threadin g.Thread
t = New Threading.Threa d(AddressOf Qry.GetOracleDa taset)
t.Priority = Threading.Threa dPriority.Highe st

Qry.QueryString = TextBox1.Text
Qry.TblName = "tbl"

t.Start()

If IsNothing(Qry.D Set) Then
MsgBox("No Dataset")
Exit Sub
End If

DataGrid1.DataS ource = Qry.DSet.Tables (Qry.TblName)
WaitForm.Close( )

End Sub



Apr 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2378
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 things. The method I am writing queries a large dataset. As part of my feedback to the user, I am updating the status bar when the connection is made and the dataset is actually retrieved. The dataset retrieval method I have placed on a separate...
0
1476
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 into a background thread and get other data out and also update the main thread on which the main form was created. It seems to work fine. The basic function of the app is cheesy, I didn't spend any time on exception handling. northwind.mdb...
3
1221
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 while the UI continues on it's merry way. I created a basic thread just as an initial test and I half expected it to crash - and it did. My problem is I don't understand why and that's making it hard to debug. The whole thing crashes (I get the old...
4
3229
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 return data from an external sql database...exactly what I am doing. This example used the System.Threading namespace and thread.start etc What are the pro's and con's of using/choosing either option? They both 'appear' to create a process on a new...
0
8269
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8203
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8512
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7203
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2630
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1515
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.