dbTalk Databases Forums  

Proper cursor definitions for table updates/inserts?

comp.database.ms-sqlserver comp.database.ms-sqlserver


Discuss Proper cursor definitions for table updates/inserts? in the comp.database.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mark Findlay
 
Posts: n/a

Default Proper cursor definitions for table updates/inserts? - 05-10-2007 , 01:11 PM






Our web site performs numerous updates, inserts, deletes and the site is
quite heavily used. From time to time users are receiving an unusual error
along the lines of "can not perform update when object is closed" when an
I/O occurs. We're concerned that we're not managing our cursors correctly to
allow for the clean update/insert/delete of records while others are
viewing/updating.

We don't set any explicit isolation values, we just use the defaults, but
perhaps we need to refine our isolation levels?

Here is a typical read:
------------------------

' Create the ADO objects
Set SQLConn = Server.CreateObject("ADODB.Connection")

' fetch the connection string to the SQL database
sDSN=GetSQLDSNString()
' Open the SQL database
SQLConn.Open sDSN
if Err.Number <> 0 then
sLastErrorMsg = "Error opening SQL Connection "
set SQLConn=nothing
exit function
end if

Set rsSQL = Server.CreateObject("ADODB.Recordset")

' open the recordset
rsSQL.Open sSQL,SQLConn

' able to open the recordset?
if err.number<>0 then
sLastErrorMsg="Error: Unable to open recordset "
else
if rsSQL.EOF then
sLastErrorMsg="There are currently no records defined for the query: " &
sSQL
else
' found: GetRows, and get row and column counts
arrData = rsSQL.GetRows()
nItemColCount=ubound(arrData,1)
nItemRowCount=ubound(arrData,2)
end if ' if rsSQL.EOF
end if ' if err.number<>0

rsSQL.close
set rsSQL=nothing
SQLConn.close
set SQLConn=nothing

---------- end of read example --------------

At the same time, other users could be inserting records, using the code
below (again, using defaults for isolation levels):

' Create the ADO objects
Set SQLConn = Server.CreateObject("ADODB.Connection")

err.clear
' fetch the connection string to the SQL database
sDSN=GetSQLDSNString()
' Open the SQL database
SQLConn.Open sDSN
if Err.Number <> 0 then
exit function
end if

SQLConn.Execute sSQL, , &H00000080 ' &H00000080 means no rows returned

SQLConn.close
set SQLConn=nothing

-------- end of insert example ------------------------

Are the examples above too generic to be effective in a high-volume,
high-I/O environment? Should we be using explicit isolation levels just as a
manner of course anyway? If so, could you recommend the best values to use?

Many thanks!




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.