Results 1 to 12 of 12

Thread: adUseServer or adUseClient ???

  1. #1

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    adUseServer or adUseClient ???

    Dear All,

    I would like to ask about ADO connection. I'm using ADO version 2.1 for my Visual Basic application / project.

    My question is...
    Are there any differences between :

    ===================================
    Connection.CursorLocation = adUseServer

    and

    Connection.CursorLocation = adUseClient
    ===================================

    What are the differences between two of them... ???
    Which one is faster ???
    Will it impact the speed of my application while I'm using adUseServer or while I'm using adUseClient ???

    Thx in advance nd Need reply / answer....

    Regards,
    Wille
    Regards,
    [-w-]

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    A database server's strength is its ability to process very quickly and efficiently. To take advantage of this server side recordets are usually more efficient, also make sure you only create recordsets with the minimum number of records possible.

    To really ram up performance and scalablilty to max, manage concurrency yourself and only ever use serverside, forwards only recordsets with optimistic locking.

    You may need client side recordsets if you want to create disconnected recordsets. Other than this stick to server side recordsets (the default for ADO).

  3. #3

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    Thx...

    But, I've just tried to use adUseServer. But, when I goes with begintrans and committrans, it returns with an error... Here is a piece of my coding.... :

    Code:
    Dim myConn as New ADODB.Connection
    
    myConn.CursorLocation = adUserServer
    myConn.Mode = adModeReadWrite
    
    myConn.Open "Driver={SQL Server}; server=mySvr; database=myDB; uid=myUID; pwd=myPWD"
    The code above is to open my Connection in ADO.

    then, at a module, here it is :

    Code:
    ....
    
    Do while not myRec1.EOF
         myConn.BeginTrans
         
         myConn.Execute "mysQLstatement update goes here"
         
         myConn.CommitTrans
         
         myRec1.MoveNext
    Loop
    
    ....
    Then, when I run, there'll be an error. The error is Cathastropic Failure .....blablabla.......

    hmm...
    But, If I put the begintrans before do, and committrans after Loop, my coding will run okay.

    Different case if I use adUseClient, the above code will run verywell without any error....

    Regards,
    Wille
    Regards,
    [-w-]

  4. #4
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    I can't help you there, I do all transactions via stored procs sitting on the server rather than in vb code.

  5. #5

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    sure...
    my sql statement, I put them on store procs...
    but, to execute the store procedure from visual basic,
    we need to use :

    Connection.Execute "storeproc_name"

    Am I right ?

    If I execute from vb using above statement, should I use begintrans and committrans again ?

    because, I need begintrans and committrans, so when my program goes an error, I still can rollback the transactions, using rollbacktrans.

    ???

    Wille
    Regards,
    [-w-]

  6. #6

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    helloooo
    anybody who knows this ?
    experts ?
    guru(s) ?

    knock knock ???

    Wille
    Regards,
    [-w-]

  7. #7
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Well if the transaction is rolledback, then you just get the stored proc to raise and error or you could also use the return value or output parameter to pass back the info.

    Then once you have the sp (where all the work really is) you create a command object with ado, use the append method for best performance to pass parameters to and from the stored proc. If the stored proc doesn't raise an error you know it has executed, otherwise the transaction was rolled back.

    All the work is done by the server and not via VB. You just use ADO to connect and execute the sp, and return any errors/return values/output parameters.

  8. #8

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    okay..
    but, I don't know how to use OUTPUT parameters in store procedure(s)

    do u know how ?

    and could I have some easy / simple code to show how to use adUseServer and how to execute SQL Statement using a connection without "Cathastropic Failure" error notice ?

    Thx in advanced Nucleus,....
    nd I still need help...

    Wille
    Regards,
    [-w-]

  9. #9
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Here is an example that returns an output parameter:

    VB Code:
    1. Public Function AddNewMember() As Long
    2.  ' Function adds a new member to the database
    3.  ' Returns the new member Id on success, or 0 if not successful
    4.  Dim cn         As ADODB.Connection
    5.  Dim cmd        As ADODB.Command
    6.  Dim prm        As ADODB.Parameter
    7.  Dim er         As ADODB.Error
    8.  Dim lRecs      As Long
    9.  Dim NewId      As Long
    10.  
    11.  Set cn = New ADODB.Connection
    12.  cn.Open sConnection
    13.  
    14.  If cn.state = adStateOpen Then
    15.    
    16.     Set cmd = New ADODB.Command
    17.     cmd.ActiveConnection = cn
    18.     cmd.CommandText = "spnewmember"
    19.     cmd.CommandType = adCmdStoredProc
    20.    
    21.     '@ipMemberDateJoined datetime
    22.     Set prm = cmd.CreateParameter("MemDateJoined", adDate, adParamInput, , Date)
    23.     cmd.Parameters.Append prm
    24.    
    25.     '@ipMemberFirstName nvarchar(200),
    26.     Set prm = cmd.CreateParameter("MemFirstName", adVarWChar, adParamInput, 200, Me.MemberFirstName)
    27.     cmd.Parameters.Append prm
    28.    
    29.     '@ipMemberLastName nvarchar(200),
    30.     Set prm = cmd.CreateParameter("MemLastName", adVarWChar, adParamInput, 200, Me.MemberLastName)
    31.     cmd.Parameters.Append prm
    32.    
    33.     '@ipMemberMiddleName nvarchar(200),
    34.     Set prm = cmd.CreateParameter("MemMiddleName", adVarWChar, adParamInput, 200, Me.MemberMiddleName)
    35.     cmd.Parameters.Append prm
    36.    
    37.     '@ipMemberAddress nvarchar(1000),
    38.     Set prm = cmd.CreateParameter("MemAddress", adVarWChar, adParamInput, 1000, Me.MemberAddress)
    39.     cmd.Parameters.Append prm
    40.    
    41.     '@ipMemberPostCode nchar(4),
    42.     Set prm = cmd.CreateParameter("MemPostCode", adWChar, adParamInput, 4, Me.MemberPostcode)
    43.     cmd.Parameters.Append prm
    44.    
    45.     '@ipMemberPhone nvarchar(50),
    46.     Set prm = cmd.CreateParameter("MemPhoneHome", adVarWChar, adParamInput, 50, Me.MemberPhoneHome)
    47.     cmd.Parameters.Append prm
    48.    
    49.     Set prm = cmd.CreateParameter("MemPhoneWork", adVarWChar, adParamInput, 50, Me.MemberPhoneWork)
    50.     cmd.Parameters.Append prm
    51.    
    52.     Set prm = cmd.CreateParameter("MemPhoneMobile", adVarWChar, adParamInput, 50, Me.MemberPhoneMobile)
    53.     cmd.Parameters.Append prm
    54.    
    55.     '@ipMemberSex bit,
    56.     Set prm = cmd.CreateParameter("MemSex", adBoolean, adParamInput, , Me.MemberSex)
    57.     cmd.Parameters.Append prm
    58.    
    59.     '@ipMemberSessions int,
    60.     Set prm = cmd.CreateParameter("MemSessions", adInteger, adParamInput, , Me.MemberSessions)
    61.     cmd.Parameters.Append prm
    62.    
    63.     '@ipMemberConcurrencyId int,
    64.     Set prm = cmd.CreateParameter("MemConcurrencyId", adInteger, adParamInput, , 0)
    65.     cmd.Parameters.Append prm
    66.    
    67.     ' @opMemberId int OUTPUT
    68.     ' Important note output parameter doesn't require size or value
    69.     Set prm = cmd.CreateParameter("opMemberId", adInteger, adParamOutput)
    70.     cmd.Parameters.Append prm
    71.    
    72.     'Make sure you tell it no records returned by stored proc
    73.     cmd.Execute lRecs, , adExecuteNoRecords
    74.    
    75.     If lRecs Then
    76.         Me.MemberId = cmd.Parameters("opMemberId")
    77.         AddNewMember = cmd.Parameters("opMemberId")
    78.     Else
    79.         AddNewMember = 0
    80.     End If
    81.    
    82.     cn.Close
    83.    
    84.     Set prm = Nothing
    85.     Set cmd = Nothing
    86.     Set cn = Nothing
    87.  
    88.  Else
    89.     ' If the connection didn't open A-OK, then
    90.     ' Display all the errors in the connection object
    91.     For Each er In cn.Errors
    92.         MsgBox er.Description
    93.     Next
    94.  End If
    95. End Function

  10. #10

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    Well,
    I will try for it...
    but....
    Didn't your coding makes an output ?

    why did you say (in your code), I should make sure I tell it no records returned by stored proc ???

    Is it just work out when we want to add / append / insert, delete, and update our recordset ?

    How about if I want to query the recordset ?
    Then, what is the real function of OUTPUT parameter ?
    coz I can't figure out the function of that statement.

    Sorry to bother,
    but I still do not understand....
    anybody could help me with this kinda problem ?
    Nucleus ? Serge ? anybody ?


    Regards,
    Wille
    Regards,
    [-w-]

  11. #11
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Here is where the output parameter is created:
    ' @opMemberId int OUTPUT
    ' Important note output parameter doesn't require size or value
    Set prm = cmd.CreateParameter("opMemberId", adInteger, adParamOutput)
    cmd.Parameters.Append prm


    In this case the ouput parameter returns the id of the new record created by the stored proc.


    why did you say (in your code), I should make sure I tell it no records returned by stored proc ???
    In this case the sp inserts a new record into a table, so it doesn't return any records. By telling ado that no records are returned it makes the process faster.

  12. #12

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    okay....
    I got the point of OUTPUT parameters....
    Thx...

    And I want to ask a question again due to your coding....

    What is lRec ?
    is it a recordset ? because, I see that you define it as Long....
    and I see that u use it at cmd.execute

    I don't quite understand about below statement :

    Code:
    cmd.execute lRecs, , adExecuteNoRecords
    Thx in reply again....
    Regards,
    Wille
    Regards,
    [-w-]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width