Nicholas,
Thanks, ya actually I do establish the connection on the thread that will
access it.
Below is a general idea of what I am doing, Console.WriteLine actually will
duplicate each selected record.
private void button3_Click(object sender, System.EventArgs e)
{
ThreadStart DBThread = new ThreadStart(StartDBDelegate) ;
Thread DB = new Thread(DBThread) ;
DB.Start();
}
public void StartDBDelegate)()
{
Invoke(new UpdateLoadTableDelegate(RunUpdateNow));
}
public void RunUpdateNow()
{
string source =
"server=testserver;uid=testuid;pwd=testpassword;da tabase=TestDB";
string selectconn1 = "SELECT TestID as dbTestID FROM TestTable"
SqlConnection conn1 = new SqlConnection(source);
conn1.Open();
SqlCommand executeconn1 = new SqlCommand(selectconn1,conn1);
SqlDataReader Connection1 = executeconn1.ExecuteReader();
while(Connection1.Read())
{
Console.WriteLine (Connection1[0].ToString())
}
}
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Oq**************@TK2MSFTNGP12.phx.gbl...
Matt,
While the data reader is not thread safe (it says as much in the
documentation), I think that this stems from the connection, and not the
reader itself. You should be marshaling the call across threads, or
establishing the connection on the thread that will access it.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Matt" <mi*****@nospam.yahoo.com> wrote in message
news:OA**************@tk2msftngp13.phx.gbl... I am using SQLDataReader to do a rather simple select statement, and
then running an update in the while loop for the Read method.
When I place the SQLDataReader in a thread delegate or not, it always
pulls duplicates for example my database contains the following:
TestID
1
2
3
And I output my values
string strTestID = "";
while(Connection1.Read())
{
strTest = Connection1[0].ToString();
}
It will output
1
1
2
2
3
3
If I take this out of a thread it will output like it should
1
2
3
Any ideas on what might be going on?