linq2db / linq2db.LINQPad

linq2db.LINQPad is a driver for LINQPad.
MIT License
74 stars 23 forks source link

not thread safe? #45

Closed yuzd closed 3 years ago

yuzd commented 3 years ago

Parallel.ForEach(rdbList, new ParallelOptions() { MaxDegreeOfParallelism = 4 }, (rdb, loopState) =>
{
    this.Insert(new test
            {
                Guid = guid,
                DataChange_LastTime = DateTime.Now,
            });
});

err:

Cannot set MySqlCommand.CommandText when there is an open DataReader for this command; it must be closed first.

MaceWindu commented 3 years ago

No, database connections are not thread-safe

yuzd commented 3 years ago
//in linqpad you must new connection by selft to make sure thread-safe

    using DataConnection db = new DataConnection("MySqlConnector","Server=127.0.0.1;Port=3306xxxxxxxxxxxxxxxxxxx");
MaceWindu commented 3 years ago

To clarify it a bit: database connections in general and in ADO.NET specifically not designed to be thread safe and I actually not aware of any provider to declare being thread-safe in this area. And because DataConnection is an abstraction over database connection, it is also not thread-safe.

yuzd commented 3 years ago

ok i got it.. thanks