Toon posts:

Transactie en meerdere recordsets (ASP + SQL server

Pagina: 1
Acties:

Verwijderd

Topicstarter
Beste mensen,

Ik heb een probleem met het porten van een content-management systeem van Access naar SQL-server. Het probleem zit hem in de volgende code:

ASP-function:
ASP.NET Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
Dim adoCnPublish
    Dim adoDocRs
    Dim adoPubRs
    
    set adoCnPublish = server.CreateObject("ADODB.Connection")
    set adoDocRs = Server.CreateObject("ADODB.Recordset")
    set adoPubRs = server.CreateObject("ADODB.Recordset")
    
    adoCnPublish.Open strConn   
    
    adoCnPublish.BeginTrans
    
    'delete published document if any
    strSQL = "DELETE FROM document_published WHERE "
    strSQL = strSQL & "document_id = " & ID
    'on error resume next
    'adoCnPublish.execute(strSQL)
    if err.number <> 0 then
        adoCnPublish.RollbackTrans
        HandleError adoCnPublish,"common.asp - PublishDocument(ID) - Delete published document"
    end if
    

    'publish document now (insert into document_published)
    strSQL = "SELECT * FROM document WHERE document_id = " & ID
    'on error resume next
    set adoDocRs = adoCnPublish.execute(strSQL)
    if err.number <> 0 then
        adoDocRs.Close
        set adoDocRs = nothing
        adoCnPublish.RollbackTrans
        HandleError adoCnPublish,"common.asp - PublishDocument(ID) - Select document"
    end if
    
    if not adoDocRs.EOF then
    
        'update document table
        'increment the version (the first segment +1 & the second segment=0)
        sVersion = adoDocRs("version")
        sFirstSegment = split(sVersion,".")(0)
        nSecondSegment = clng(split(sVersion,".")(1))
        sFirstSegment = sFirstSegment + 1
        sVersion = sFirstSegment & ".0"
        
        nParentDocID = adoDocRs("parent_document_id")


        adoPubRs.ActiveConnection = adoCnPublish
        adoPubRs.CursorType = 2 'static cursor
        adoPubRs.LockType = 3 'optimistic locking

        adoPubRs.Open "SELECT * FROM document_published WHERE 1<>1"
        adoPubRs.AddNew
        adoPubRs("document_id") = adoDocRs("document_id")
        adoPubRs("parent_document_id") = adoDocRs("parent_document_id")
        adoPubRs("position") = adoDocRs("position")
        adoPubRs("template_id") = adoDocRs("template_id")
        adoPubRs("type") = adoDocRs("type")
        adoPubRs("title") = adoDocRs("title")
        adoPubRs("sub_title") = adoDocRs("sub_title")
        adoPubRs("link_text") = adoDocRs("link_text")
        adoPubRs("abstract") = adoDocRs("abstract")
        adoPubRs("content") = adoDocRs("content")
        adoPubRs("search_keywords") = adoDocRs("search_keywords")
        adoPubRs("search_description") = adoDocRs("search_description")
        adoPubRs("author_id") = adoDocRs("author_id")
        adoPubRs("last_updated_by") = adoDocRs("last_updated_by")
        adoPubRs("date_created") = adoDocRs("date_created")
        adoPubRs("date_last_updated") = adoDocRs("date_last_updated")
        adoPubRs("date_published") = ConvertDate(now())
        adoPubRs("file_name") = adoDocRs("file_name")
        adoPubRs("file_size") = adoDocRs("file_size")
        adoPubRs("public") = adoDocRs("public")
        adoPubRs("version") = sVersion ' increased version
        adoPubRs("date_start") = adoDocRs("date_start")
        adoPubRs("date_end") = adoDocRs("date_end")
        adoPubRs("hidden") = adoDocRs("hidden")
        
        'on error resume next
        adoPubRs.Update
        if err.number <> 0 then
            adoPubRs.Close
            adoDocRs.Close
            set adoPubRs = nothing
            set adoDocRs = nothing
            adoCnPublish.RollbackTrans
            HandleError adoCnPublish,"common.asp - PublishDocument(ID) - Add published document"
        end if
        
        adoPubRs.Close 
    end if
    
    adoDocRs.Close 
    
    'Rearrange position ~~~~~~~~~~~
    if Not IsNull(nParentDocID) then 'if not a contentblock, etc    
        strSQL = "SELECT document_id, position FROM document " & _
                " WHERE parent_document_id = " & nParentDocID & _
                " AND type='content' ORDER BY position ASC"
        set adoRsIn = adoCnPublish.Execute(strSQL)
        do while not adoRsIn.EOF
            strSQL = "UPDATE document_published SET position = " & adoRsIn("position") & _
                    " WHERE document_id = " & adoRsIn("document_id")
            on error resume next
            adoCnPublish.Execute strSQL
            if err.number <> 0 then
                adoCnPublish.RollbackTrans
                HandleError adoCnPublish,"common.asp - PublishDocument(ID) - Rearrange position"
            end if  
            adoRsIn.MoveNext 
        loop
        adoRsIn.Close
        set adoRsIn = nothing   
    end if
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    set adoDocRs = nothing
    set adoPubRs = nothing
    
    'set approval status to "published" and increased version
    strSQL = "UPDATE document SET approval_status = 'published'"
    strSQL = strSQL & ",date_last_published = '" & ConvertDate(now()) & "' "
    strSQL = strSQL & ",version='" & sVersion & "' "
    strSQL = strSQL & "WHERE document_id = " & ID
    on error resume next
    adoCnPublish.Execute (strSQL)
    if err.number <> 0 then
        adoCnPublish.RollbackTrans
        HandleError adoCnPublish,"common.asp - PublishDocument(ID) - Update approval status to 'published'"
    end if
    
    adoCnPublish.CommitTrans
    adoCnPublish.Close
    set adoCnPublish = nothing
    
end function

Ik krijg namelijk de volgende foutmelding: "Een transactie kan niet meerdere recordsets met dit cursortype bevatten. Wijzig het cursortype, voer de transactie door of sluit een van de recordsets."

Ik heb al naar informatie gezocht op het internet, maar dit heeft me tot nu toe nog niet geholpen bij het oplossen van het probleem. In de knowledgebase van Microsoft kwam ik het volgende artikel tegen http://support.microsoft....aspx?scid=kb;en-us;180843 wat exact hetzelfde probleem beschrijft, maar ik kwam hier niet uit: Hoe moet ik dit toepassen op mijn eigen stuk code? Ik maak trouwens gebruik van asp en SQL server. Het rare is dat bovenstaande code perfect werkte met access en nu allerlei problemen geeft

Iemand een idee? Alvast bedankt! ;)

[ Voor 13% gewijzigd door NMe op 07-05-2005 22:43 . Reden: Code tags ]


  • NMe
  • Registratie: Februari 2004
  • Laatst online: 15-04 22:07

NMe

Quia Ego Sic Dico.

Op welke regel gaat het mis? Traceer dat eerst eens; we gaan hier niet 136 regels code voor je debuggen. Zou je volgende keer ook [code]-tags willen gebruiken in plaats van een tabel? Dit in verband met uitlijning en regelnummers, dat maakt je code een stuk leesbaarder. :)

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Verwijderd

Topicstarter
Als eerste mijn excuses voor de beperkte informatie.

De fout zit hem op regel 52.
De exacte foutmelding is dan: Een transactie kan niet meerdere recordsets met dit cursortype bevatten. Wijzig het cursortype, voer de transactie door of sluit een van de recordsets.

Helaas heb ik geen engelse foutmeldingen; meestal is het opzoeken van informatie dan gemakkelijker.

Mochten jullie nog meer informatie nodig hebben, dan hoor ik dat uiteraard. Ik hoop dat jullie hier iets mee kunnen. Bij voorbaat dank.

  • mulder
  • Registratie: Augustus 2001
  • Laatst online: 23:28

mulder

ik spuug op het trottoir

Als je nou eens met het Command object gaat werken ipv Recordsets

oogjes open, snaveltjes dicht


  • avon
  • Registratie: November 2002
  • Laatst online: 27-06-2025
code:
1
2
adoPubRs.Open "SELECT * FROM document_published WHERE 1<>1"
adoPubRs.AddNew


Volgens mij ga je daar de mist in... Eerst een Select (met een voor mij onbekende WHERE
clausule) en vervolgens probeer je een nieuw record in te voegen onder dezelfde recordset.

[ Voor 7% gewijzigd door avon op 10-05-2005 08:11 ]

Gratis webwinkel beginnen? Met Onetoshop.com kunt u direct beginnen!


  • whoami
  • Registratie: December 2000
  • Laatst online: 23:00
Don Facundo schreef op dinsdag 10 mei 2005 @ 07:59:
Als je nou eens met het Command object gaat werken ipv Recordsets
Idd, ik zou ook gewoon een INSERT query uitvoeren, ipv met die AddNew() te gaan prutsen.

https://fgheysels.github.io/

Pagina: 1