Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

Locktype with Command-object

Hi,

I´m using a the Execute-method of the Command-object to call a stored procedure that returns a couple of parameters and a recordset. The problem is that the recordset is set to adLockReadOnly and can´t be updated. Is it only possible to set Locktype using the open-method of the Recordset or what?
I want to use a disconnected recordset and modify it on the client and then update the database(SQL7) with updatebatch.

0
polksolk
Asked:
polksolk
  • 4
  • 3
  • 2
  • +1
1 Solution
 
mmipsCommented:
Yes...Follw the following example from MS

' Open employee table.
   Set rstEmployees = New ADODB.Recordset
   rstEmployees.CursorType = adOpenKeyset
   rstEmployees.LockType = adLockOptimistic
   rstEmployees.Open "employee", cnn1, , , adCmdTable
0
 
mmipsCommented:
To make it a disconnected recordset set the connection object cursor type to aduseclient. Then after you obtain the recordset set the recordset's connection object to "nothing" then you may update records using the updateBatch method...
0
 
polksolkAuthor Commented:
I know how to make a disconnected recordset. The problem is how to set the Locktype-property when I use the command.execute method and not the open-method of the recordset. Like this:

Set rs = command.Execute

When I do like this Locktype is set to read only.
Here´s my code:


Set comOld = New Command
     With comOld
          .CommandType = adCmdStoredProc
          .CommandText = "GetOldOrder"  ' name on stored procedure
   
          ' skapar och lägger till input-parametrar och anger värde
          .Parameters.Append .CreateParameter("avdID", adInteger, adParamInput, , AvdID)
          .Parameters.Append .CreateParameter("orderno", adInteger, adParamInput, , OrderNr)
          .Parameters.Append .CreateParameter("totalsuma", adCurrency, adParamOutput)
          .Parameters.Append .CreateParameter("control", adInteger, adParamOutput)
          .Parameters.Append .CreateParameter("contact", adVarChar, adParamOutput, 40)
          .Parameters.Append .CreateParameter("orderstatus", adVarChar, adParamOutput, 48)
          .Parameters.Append .CreateParameter("sender", adVarChar, adParamOutput, 40)
         
          .ActiveConnection = cn
          Set rsLog = .Execute
          OrderSum = .Parameters("Totalsum").Value
          iKontroll = .Parameters("control").Value
          sjhkontakt = .Parameters("contact").Value
          Beststatus = .Parameters("orderstatus").Value
          Sandare = .Parameters("sender").Value
         
       End With
       Set comOld = Nothing
    Set rsLog.ActiveConnection = Nothing
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
p_biggelaarCommented:
Forget about Set rs=Command.Execute

Your code should look like

'Do everything with you're command that's necessary then:

Set rs=new adodb.recordset
rs.CursorLocation=adUseClient
rs.CursorType=adOpenKeyset
rs.LockType=adLockBatchOptimistic
rs.open comOld
0
 
mmipsCommented:
As I stated earlier you do not want to use the rs = command.execute...Use the open method for the recordset to allow you to set the cursor type and lockType...
0
 
p_biggelaarCommented:
To mmips:

The difference between my comment and what you suggested is that I open the command (rs.Open comOld) while you describe the 'standard' open syntax.

rstEmployees.Open "employee", cnn1, , , adCmdTable

polksolk needs to use the command object, because he uses parameters, so your example is not accurate in the way that:
- you open a table
- when opening a command, you MUST use the connection specified by the command object, so even replacing the table name by the object would result in an error in that example.

Those were the main reasons why I posted my first comment. I wanted to tell you this, because I don't want to give you the impression that I was only 'copying' your comment.
0
 
troywillmotCommented:
If you have VB6, you could use DED (Data Environment Designer) which has a lock type property on the property page for a command if the returning recordset property is true. I assume that this affects the lock type for the recordset returned.
0
 
troywillmotCommented:
By the way, I don't use DED myself, 'cause I don't like it - but in cases where my boss has insisted I try it I haven't had any problems.
0
 
polksolkAuthor Commented:
Thanks!
Works great.
0
 
p_biggelaarCommented:
you're welcome...
0
 
mmipsCommented:
p_biggelaar,

Unfortunately I cut and pasted to much...I wanted to show how to set the values for a recordset...I know that He was using Stored Proceedures and that particular open method would not work...If you take the open method off of you comment it was a copy...And my second comment stated to use the open method for a recordset...rather than the execute method...Next time I'll have to be more careful about my cut and paste examples...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now