c# - DataSet raises NoNullAllowedException even if a value is passed! -


I am writing a game server for which many players are connected. I load the DB in a dataset (strong type). Whenever a player logs, I add a new row in the message table using the table adapter.

  code var newRow = _db.Messages.NewMessagesRow (); // _db is a robust-type-dataset {newRow.Title = title; NewRow.Text = text; NewRow.ReceiverUID = Receiver UID; NewRow.Deleted = false; } // I lock _db.Messages, so it happens at one time lock (_db.Messages) {_db.Messages.AddMessagesRow (newRow); _adapterMessages.Connection.Open (); _adapterMessages.Update (newRow); NewRow.MessageID = (Int64) _adapterMessages.GetIdentity (); NewRow.AcceptChanges (); _adapterMessages.Connection.Close (); }  

New Message () and AddMessagesRow () are generated automatically by VS. I did this by adding a dataset item (.xsd file) and dragging all the DB tables.

  Public Messaging News Rou () {Return ((Message) (this.NewRow ()); } Public Zero AddMessagesRow (MessagesRow line) {this.Rows.Add (line); }  

_db is a dataset (strong-typed, automatically generated by VS) _db.Messages is a datatable.

While doing the test, give me the

  system.data.Nonumed exception: The column does not allow 'deleted' tap. System.Data.DataColumn.CheckNullable (DataRow line) on System.Data.DataTable.RaiseRowChanging (...) on System.Data.DataTable.SetNewRecordWorker (...) on System.Data.DataTable.InstertRow (...) On the System.Data.DataRowCollection.Add (DataRow line) Server.Database.MessagesDataTable.AddMessagesRow (MessagesRow Row)  

AddMessagesRow () is called in the above code only, and I always delete Set the wrong for the selected column, but still receive this message ...

I do not use elsewhere / adapter, but there are other adapter (_adapterUsers, _adapterMatches, ... etc) Concurrent form Area can be used.

I do not get an exception every time, but if the server runs for some time (like> 30 minutes) with about 1,000 concurrent players, it happens.

Any help or advice would be greatly appreciated thanks :)

I Understand the root cause of the problem. I thought DataTable.NewRow () thread was secure, but it is not.

Then change the code as above:

  lock (_db.Messages) {var NewRow = _db.Messages.NewMessagesRow (); {NewRow.Title = Title; NewRow.Text = text; NewRow.ReceiverUID = Receiver UID; NewRow.Deleted = false; } _db.Messages.AddMessagesRow (newRow); _adapterMessages.Connection.Open (); _adapterMessages.Update (newRow); NewRow.MessageID = (Int64) _adapterMessages.GetIdentity (); NewRow.AcceptChanges (); _adapterMessages.Connection.Close (); }  

You can refer to this issue ..


Comments