- Q Why is an increase in inventory shown as a negative amount in the statement of cash flows?
- Q What does rmi stand for?
- Q Which of the following is a disadvantage of machine language?
- Q Something is wrong ____him.
- Q Gondwanaland does not include-
- Q The founder of the daily ‘Swadeshabhimani’:
- Q Name the fabulous city constructed by Vishwakarma on top of the mountain Trikuta?
- Q How to change the text of an element with a function?
- Q Why is continuous improvement necessary?
- Q Explain different categories of operators in java?
- Q What is a cremnophobe afraid of
Question
When should I use CreateObject to create my recordset objects?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Answers
A quick note: NEVER store a recordset in the session object. For a discussion of this see:
http://www.microsoft.com/mind/1198/ado/ado.htm (tip #6)
KB #176056
Most data access tasks can be implemented by using the execute method of the connection object. Why would we
want to do this? Well, for one, there is extra overhead in using a recordset object for UPDATE and INSERT
functionality. This is because the provider has to translate your code into an equivalent T-SQL statement anyway
(the database itself has no knowledge of "addNew" and similar methods). Also, there are many dangerous locks
associated with recordsets... most of which are not necessary (especially when performing an INSERT or UPDATE).
Your goal should be to get in, tweak your data, and get out as quickly as possible. Using direct statements is the
quickest way to do this, since there is much less overhead and no locks associated with your activity.
Another benefit of using an INSERT or UPDATE statement is that it is much easier to debug. You can change
conn.execute(sql) to response.write(sql) and immediately see why your statement is throwing an error. With a multiline
transaction using a recordset object, it is translated to an INSERT or UPDATE statement (inefficiently!) on the
DB side, so there is no straightforward way to trap errors at the code level.
To use the connection object, simply design a transact-SQL statement for the action you want to use and
implement it like so:
<%
sql = "INSERT INTO (fields) VALUES (values)"
http://www.microsoft.com/mind/1198/ado/ado.htm (tip #6)
KB #176056
Most data access tasks can be implemented by using the execute method of the connection object. Why would we
want to do this? Well, for one, there is extra overhead in using a recordset object for UPDATE and INSERT
functionality. This is because the provider has to translate your code into an equivalent T-SQL statement anyway
(the database itself has no knowledge of "addNew" and similar methods). Also, there are many dangerous locks
associated with recordsets... most of which are not necessary (especially when performing an INSERT or UPDATE).
Your goal should be to get in, tweak your data, and get out as quickly as possible. Using direct statements is the
quickest way to do this, since there is much less overhead and no locks associated with your activity.
Another benefit of using an INSERT or UPDATE statement is that it is much easier to debug. You can change
conn.execute(sql) to response.write(sql) and immediately see why your statement is throwing an error. With a multiline
transaction using a recordset object, it is translated to an INSERT or UPDATE statement (inefficiently!) on the
DB side, so there is no straightforward way to trap errors at the code level.
To use the connection object, simply design a transact-SQL statement for the action you want to use and
implement it like so:
<%
sql = "INSERT INTO