Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Record Locking in VB5 (MS SQL 6.5)

Posted on 1998-12-15
8
Medium Priority
?
395 Views
Last Modified: 2013-12-25
I am using the VB5 reading MS SQL 6.5.
My Code as bellow:-

mysql = "begin transaction icm"
IMSDatabase.Execute mysql, 64

sqlselect = "select item_code, qty1, cost1, qty2, cost2, qty3, cost3,"
sqlselect = sqlselect + "qty4, cost4, qty5, cost5 from icm_cost_lot (tablockx) where "
sqlselect = sqlselect + "item_code = '" + TempItemCode2 + "'"
Set item_cost = IMSDatabase.OpenRecordset(sqlselect, 2, 64)


mysql = "update icm_cost_lot set qty" + Trim(Combo_LotNo) + " = qty" + Trim(Combo_LotNo) + " + " + Format(MainQuantity, "0.00")
mysql = mysql + " where item_code = '" + TempItemCode2 + "'"
IMSDatabase.Execute mysql, 64

mysql = "commit transaction icm"
IMSDatabase.Execute mysql, 64

This locking method is working in VB4 but in VB5, there is no error message and the locking is not working.

Anybody know the correct way of record locking in VB5 , please reply me. Thanks in advice.
0
Comment
Question by:chansb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 

Expert Comment

by:HOIMEI
ID: 1498315
Hi chansb,
    The better to way is browse through the recordset item_cost,
Check the condition of records one by one and assign the new value  of the field.  In this way, the recordset will automatically lock the record /page according to the parameter of openrecordset.
    e.g while not item_cost.EOF
                  if item_cost!itemcode = TempItemCode2 then
                       item_cost![field_name]= [new value]
                  end if
                  item_cost.movenext
          wend
Hope this help!

May
0
 

Author Comment

by:chansb
ID: 1498316
Hello HOIMEI,
Sorry that this answer is not what I want. My quention is how to lock the record in sql 6.5 database using the VB5 before we update the record.

Please note that the method I use is SQL pass thru statement.

regards,
chansb
0
 

Author Comment

by:chansb
ID: 1498317
The locking is only start after the line (execute) and before commit.

mysql = "update icm_cost_lot set qty" + Trim(Combo_LotNo) + " = qty" + Trim(Combo_LotNo) + " + " + Format(MainQuantity, "0.00")
mysql = mysql + " where item_code = '" + TempItemCode2 + "'"
THIS LINE --> IMSDatabase.Execute mysql, 64

IF in VB4 this record is lock the moment openrecordset.
eg:- Set item_cost = IMSDatabase.OpenRecordset(sqlselect, 2, 64).


regards,
chansb

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
cedricd earned 100 total points
ID: 1498318
open a recordset and edit it (vb will lock the recordset's records)
set item_cost = db.openrecordset(sql,dbopendynaset,0,dbpessimistic)
dbpessimistic : lock the records on the edit method

item_cost.edit
0
 

Author Comment

by:chansb
ID: 1498319
Hi cedricd,
The locking still after the update execte line.

Dim G_WrkSpace as workspace
Dim IMSdatabase as database

G_SQLDB = "ODBC;DATABASE=IMS;UID=sa;PWD=;DSN=IMS;"
Set G_WrkSpace = Dbengine.workspaces(0)
Set IMSDatabase = g_wrkspace.OpenDatabase("", False, False, G_SQLDB)

G_WrkSpace.BeginTrans

sqlselect = "select item_code, qty1, cost1, qty2, cost2, qty3, cost3,"
sqlselect = sqlselect + "qty4, cost4, qty5, cost5 from icm_cost_lot where " 
sqlselect = sqlselect + "item_code = '" + TempItemCode2 + "'"
Set item_cost = IMSDatabase.OpenRecordset(sqlselect, dbOpenDynaset, 0, dbPessimistic)


mysql = "update icm_cost_lot set qty" + Trim(Combo_LotNo) + " = qty" + Trim(Combo_LotNo) + " + " + Format(MainQuantity, "0.00")
    mysql = mysql + " where item_code = '" + TempItemCode2 + "'"
item_cost.edit
THIS LINE --> IMSDatabase.Execute mysql, 64
item_cost.Update
g_wrkspace.CommitTrans
   




0
 
LVL 2

Expert Comment

by:cedricd
ID: 1498320
try this then :

set g_wrkspace = createworkspace("Name","","",dbuseodbc)
Set IMSDatabase = g_wrkspace.OpenDatabase("", False, False, G_SQLDB)

G_WrkSpace.BeginTrans

sqlselect = "select item_code, qty1, cost1, qty2, cost2, qty3, cost3,"
sqlselect = sqlselect + "qty4, cost4, qty5, cost5 from icm_cost_lot where " 
sqlselect = sqlselect + "item_code = '" + TempItemCode2 + "'"
Set item_cost = IMSDatabase.OpenRecordset(sqlselect, dbOpenDynaset, 0, dbPessimistic --> locked on edit (or dboptimistic to lock on update)


mysql = "update icm_cost_lot set qty" + Trim(Combo_LotNo) + " = qty" + Trim(Combo_LotNo) + " + " + Format(MainQuantity, "0.00")
    mysql = mysql + " where item_code = '" + TempItemCode2 + "'"
item_cost.edit

IMSDatabase.Execute mysql, dbFailOnError (as it's use on a transaction, it's locked until the committrans)
      
item_cost.Update (locked)
g_wrkspace.CommitTrans

0
 

Author Comment

by:chansb
ID: 1498321
Hi cedricd,
set g_wrkspace = createworkspace("Name","","",dbuseodbc)
Set IMSDatabase = g_wrkspace.OpenDatabase("", False, False, G_SQLDB)

G_WrkSpace.BeginTrans

sqlselect = "select item_code, qty1, cost1, qty2, cost2, qty3, cost3,"
sqlselect = sqlselect + "qty4, cost4, qty5, cost5 from icm_cost_lot where " 
sqlselect = sqlselect + "item_code = '" + TempItemCode2 + "'"
Set item_cost = IMSDatabase.OpenRecordset(sqlselect, dbOpenDynaset, 0, dbPessimistic)


mysql = "update icm_cost_lot set qty" + Trim(Combo_LotNo) + " = qty" + Trim(Combo_LotNo) + " + " + Format(MainQuantity, "0.00")
    mysql = mysql + " where item_code = '" + TempItemCode2 + "'"
DID NOT LOCK AT HERE -> item_cost.edit

START LOACK AT HERE-> IMSDatabase.Execute mysql, dbFailOnError

item_cost.Update
g_wrkspace.CommitTrans
0
 
LVL 2

Expert Comment

by:cedricd
ID: 1498322
normally, during the update command, the records which there are being affected by this will be locked.
if it doesn't work then open a recordset like
set rs = db.openrecordset("Select qty from icm_cost_lot where item_code = '"+tempitemcode2"'",dbopendynaset,0,dbpessimistic)
while ...
    rs.edit
    rs("qty")=...
    rs.update
wend

it's a little less fast but you control the locking yourself.
it's all i can propose you.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question