Search code examples
formsms-accessunbound

Problem with connecting ADODB.Recordset to a forms RECORDSET on the On Open event of the form


I have an access project that is "linked" to a SQL database that now works like a charm. The last problem I solved was, making sure any Boolean fields be turned to bits with default of 0, and adding the TIMESTAMP in SQL due to the fact that ACCESS is not so much of a genius with record locking (so I was told) .

Now that I tried to connect direct to SQL server by using an ADODB.Recordset and setting the forms.recordset to the recordset, at the OnOpen event of the form, (this recordset runs a stored procedure in SQL, I get the data fine but get the error locking (write conflict) back.

This ADODB.Recordset cursorlocation is set to "adUseClient".

Obviously I no longer have the forms recordsource attached or assigned to the linked SQL table anymore.

Am I missing something? do I need to assign anything to the forms recordsource?

The Idea is trying to connect directly thru the use of stored procedures instead of linked tables. thanks so much for any help.


Solution

  • The adding of timestamp is a VERY good idea. And do not confuse the term/name used timestamp to mean an actual date/time column. The correct term is "row version".

    This issue has ZERO to do with locking. The REASON why you want this column added is because then Access will use that column to determine when the record is dirty, and more imporant figure out that the record been changed. If you omit this column, then access reverts to a column by column testing approach. Not only does this cause more network traffic, but worse for real type values, due to rounding, you can get the dredged this record has been changed by another user. But, it not been changed, and even columns with floating point values will cause access to error out with that changed record.

    So, for all tables, and you even see the option included in the SSMA (the access to sql migration wizard that this option is available (and I believe it is a default).

    So yes, it is HIGH but VERY high recommended that you include/add a rowversion column to all tables - this will help Access in a HUGE way.

    And as noted, there is a long standing issue with bit fields that don't have a default setting. so, you don't want to allow bit fields to be added/created with a null value. So, ensure that there is a default value of 0 (you set this sql server side).

    Ok, now that we have the above cleared up?

    It not really all that clear as to why you want or need or are adopting a store procedure and code to load/fill up the form. You not see any better performance if you bind the form DIRECTLY to the linked table. Access will ONLY pull the reocrds you tell that form to load.

    So, bind the form directly to the linked table. Then, you can launch/open the form say to once reocrd with this:

    docmd.OpenForm "frmInvoices",,,"InvoiceNum = 123"
    

    Now, you would of course change the above "123" to some variable or some way to prompt the user for what invoice to work on.

    The invoice form will then load to the ONE record. So, even if the form bound (linked table) has 2 million rows? Only ONE record will come down the network pipe. So, all that extra work of a store procedure, creating a recordset and pulling it ? You will gain ZERO in terms of performance, but you are writing all kinds of code when it simply not required, and you not achieve any superior performance to the above one line of code that will automatic filter and ONLY pull down the record that meets the given criteria (in this example invoice number).

    So: Yes, all tables need a PK Yes, all tables should have a rowversion (but it called a timestamp column - nothing to do with the actual time). Yes, all bit fields need a default of 0 - don't allow null values.

    And last but not least? I don't see any gains in performance, or even any advantages of attempting to code your way though this by adopting store procedures and that of introducing reocrdset code when none is required, but worse will not gain you performance anyway.