S
Smokey Grindle
Say I have the code provided below
Dim connection As DbConnection = New SqlClient.SqlConnection("Data
Source=DEVELOPMENT;Database=BENE_Development;Trusted_Connection=True;")
Dim dt As New DataTable
Dim cmd As DbCommand = connection.CreateCommand
cmd.CommandText = "SELECT AccountName, accountid from accounts"
cmd.CommandType = CommandType.Text
connection.Open()
Try
dt.Load(cmd.ExecuteReader)
Catch ex As DbException
MessageBox.Show(ex.ToString)
End Try
connection.Close()
Me.lstAccounts.DataSource = dt
Me.lstAccounts.ValueMember = "accountid"
Me.lstAccounts.DisplayMember = "accountname"
which of course uses a data reader, now say I have this application in an
MDI window and this form ran its code but then the user opened up another
form that ran similar code. would the two readers clash and cause an
exception? I'm assumeing yes since they are on the same database connection
(I am using the same connection for all objects, and this is an always open
connection, the connection string above is just for the code example) so,
now I have two data readers trying to excute on a single connection. How do
I prevent them from clashing with each other? I know it is possible because
the data adapter class already does something simliar to this (please dont
tell me to just use the data adapter instead, I'm trying to learn here). How
would you go about handleing this? (I dont want to use MARS either, just
single connection with out multiple active result sets)
thanks a lot!
Dim connection As DbConnection = New SqlClient.SqlConnection("Data
Source=DEVELOPMENT;Database=BENE_Development;Trusted_Connection=True;")
Dim dt As New DataTable
Dim cmd As DbCommand = connection.CreateCommand
cmd.CommandText = "SELECT AccountName, accountid from accounts"
cmd.CommandType = CommandType.Text
connection.Open()
Try
dt.Load(cmd.ExecuteReader)
Catch ex As DbException
MessageBox.Show(ex.ToString)
End Try
connection.Close()
Me.lstAccounts.DataSource = dt
Me.lstAccounts.ValueMember = "accountid"
Me.lstAccounts.DisplayMember = "accountname"
which of course uses a data reader, now say I have this application in an
MDI window and this form ran its code but then the user opened up another
form that ran similar code. would the two readers clash and cause an
exception? I'm assumeing yes since they are on the same database connection
(I am using the same connection for all objects, and this is an always open
connection, the connection string above is just for the code example) so,
now I have two data readers trying to excute on a single connection. How do
I prevent them from clashing with each other? I know it is possible because
the data adapter class already does something simliar to this (please dont
tell me to just use the data adapter instead, I'm trying to learn here). How
would you go about handleing this? (I dont want to use MARS either, just
single connection with out multiple active result sets)
thanks a lot!