Showing posts with label updating. Show all posts
Showing posts with label updating. Show all posts

Friday, February 24, 2012

C# with ADO 2.8: Receiving "Current Recordset does not support updating"

Hi All,

I was using VB6 to access a MS SQL Server database. The code worked and works fine. I then decided to migrate the code to C#.Net 2005 using ADO 2.8 (not ADO.Net). Doing that yields with the same exact code the error message, "Current Recordset does not support updating".

I did a whole bunch of Google searches and didn't see anything useful. Mainly the advice from Microsoft and others is to make sure the mode on the connection string is set to "ReadWrite", as the default is "Read Only" and to make sure to set the lock type to either optimistic or pessimistic. Still others said that the code should set the CursorLocation property of the recordset.

I can safely say that I have been setting the mode to "Read/Write" since the start and have played around with the lock type, cursor location, and open method. Nothing works on C#, BUT VB6 is so totally happy with everything.

The provider works fine, as VB6 works fine, and the lock type is also fine, so therefore the built in suggestions do not apply.

My code is:

// Connection string template. Filled in properly in real code.
strConnect = "Server={0};Database={1};"

// Set the connection properties.
this.SQLConnection.ConnectionString = strConnect;
this.SQLConnection.Provider = "SQLOLEDB";
this.SQLConnection.Mode = adModeReadWrite;

// Open the connection.
this.SQLConnection.Open(strConnect, strUserName, strPassword, -1);

=================

// Create the ADO objects needed.
dbRSAdd = new Recordset();

// Open the recordset.
dbRSAdd.Open(strTable, dbCatalog.ActiveConnection, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic, (int)CommandTypeEnum.adCmdTable);

// Cycle through each record to add.
dbRS.MoveFirst();
for (lRecord = 0; lRecord < dbRS.RecordCount; lRecord++)
{
// Add a new record.
dbRS.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);

...
}

// NOTE: The code crashes with the call to 'AddNew'.

Any advice?Hi All,

(Head between my legs.) I can't tell you how long I looked at the code only to look at the code on this post and immediately see the problem. I had two record sets. The first record set (dbRS) is read only. I made the stupid mistake of not putting dbRSAdd with the AddNew. VB6 uses a 'With' statement, whereas C# does not support a 'With' statement. My problem was that I wasn't careful in copying and pasting, when filling in the prefix before the '.'.

Oops!

Thursday, February 16, 2012

Bypassing locks when doing insert or update

Hi,

I want to bypass locks while doing Insert or Update. I am only updating a log db and I don't care about one or two fields getting junk as I won't use it later (atleast as long as I am working with my current company ;) )

I am using MS SQL 2000

I am getting too many deadlocks and messages like these

"Process ID was deadlocked with another process and has been chosen a victim. Please rerun the transaction".

Please tell me how to achieve this.

Regards,
Noorul

you can try using a 'NOLOCK' locking hint....but u have to be sure..it wont affect ur data (ACID)....

correct..and longer part will be to try and find the source of deadlocks..and remove it..

|||Have a look to see what you have in the way of indexes on your table, particularly your clustered index. Hopefully you have an id field which only increments as your clustered index, so that it never tries to move the pages around, and your inserts can just jump straight in and out again.

Updates shouldn't have to be any different - make sure you have a good indexing strategy so that the system doesn't try to lock more of the table than it needs to.

Why are you updating a log anyway? And should I assume you mean 'audit' ?

Rob|||You absolutely CANNOT bypass locking when doing UPDATES or INSERTS or DELETES. Nor would you want to. You are getting deadlocks because your code is accessing the data in differring order, you are holding transactions open too long, and/or you are not using NOLOCK hints on your SELECT statements where appropriate.|||

Please take a look at the links below on how to resolve deadlocks. You can't eliminate them by just using locking hints in your various statements. Deadlocks are typically due to errors in your execution logic.

http://support.microsoft.com/kb/832524/

http://msdn2.microsoft.com/en-us/library/aa937573(SQL.80).aspx

|||Thanks All

I read about the clustered Index from Microsoft kb 169960. I created the clustered index with 70 fill factor. It has reduced the deadlocks down to zero. Actually I have an application that has 10 threads logging the sent SMS messages into same table. My application don't read from it, it just does insert. So far, so good. With 70 fill factor, how will that affect the memory consumption?

Regards,
Noorul

Bypassing locks when doing insert or update

Hi,

I want to bypass locks while doing Insert or Update. I am only updating a log db and I don't care about one or two fields getting junk as I won't use it later (atleast as long as I am working with my current company ;) )

I am using MS SQL 2000

I am getting too many deadlocks and messages like these

"Process ID was deadlocked with another process and has been chosen a victim. Please rerun the transaction".

Please tell me how to achieve this.

Regards,
Noorul

you can try using a 'NOLOCK' locking hint....but u have to be sure..it wont affect ur data (ACID)....

correct..and longer part will be to try and find the source of deadlocks..and remove it..

|||Have a look to see what you have in the way of indexes on your table, particularly your clustered index. Hopefully you have an id field which only increments as your clustered index, so that it never tries to move the pages around, and your inserts can just jump straight in and out again.

Updates shouldn't have to be any different - make sure you have a good indexing strategy so that the system doesn't try to lock more of the table than it needs to.

Why are you updating a log anyway? And should I assume you mean 'audit' ?

Rob|||You absolutely CANNOT bypass locking when doing UPDATES or INSERTS or DELETES. Nor would you want to. You are getting deadlocks because your code is accessing the data in differring order, you are holding transactions open too long, and/or you are not using NOLOCK hints on your SELECT statements where appropriate.|||

Please take a look at the links below on how to resolve deadlocks. You can't eliminate them by just using locking hints in your various statements. Deadlocks are typically due to errors in your execution logic.

http://support.microsoft.com/kb/832524/

http://msdn2.microsoft.com/en-us/library/aa937573(SQL.80).aspx

|||Thanks All

I read about the clustered Index from Microsoft kb 169960. I created the clustered index with 70 fill factor. It has reduced the deadlocks down to zero. Actually I have an application that has 10 threads logging the sent SMS messages into same table. My application don't read from it, it just does insert. So far, so good. With 70 fill factor, how will that affect the memory consumption?

Regards,
Noorul