Bonjour à tous ...
Je réalise un prototype pour convaincre le client de réaliser une application en C#.net qui s'appuie sur des composants VB.
Je dois donc insérer des données en base depuis le composant VB mais que je controle via ma page aspx a l'aide de transaction...
J'utilise un wrapper pour attaquer mon composant VB...
L'insertion se passe bien, mais trop bien car lorsque que je ne commit pas dans ma page aspx, il insére quand même
Voici mon code C# pour ma page ASPX:
Mon wrapper :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 protected void InsertOk_Click(object sender, EventArgs e) { string resultat = string.Empty; using (TransactionScope newTransaction = new TransactionScope(TransactionScopeOption.Suppress)) { resultat = _wrapper.InsertionLigne("1"); resultat = _wrapper.InsertionLigne("2"); newTransaction.Complete(); } } protected void InsertKo_Click(object sender, EventArgs e) { string resultat = string.Empty; using (TransactionScope newTransaction = new TransactionScope(TransactionScopeOption.Suppress)) { resultat = _wrapper.InsertionLigne("3"); resultat = _wrapper.InsertionLigne("4"); } }
Et enfin mon code VB qui insére...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 <Transaction(TransactionOption.Required)> Public Class Wrapper Inherits ServicedComponent <AutoComplete()> Public Function InsertionLigne(ByVal ligne As String) As String Dim objAFP As Object Dim chaine As String Try objAFP = CreateObject("COMTest.ComTestclass") chaine = objAFP.InsertionLigne(ligne) Catch ex As Exception Throw New Exception(ex.Message) Finally Marshal.ReleaseComObject(objAFP) End Try Return chaine End Function
J'espère que quelqu'un pourra m'aider...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Public Function InsertionLigne(ByVal ligne As String) On Error GoTo GestionErreur Dim objBDD As Object Set objBDD = GetObjectContext.CreateInstance("TESTBDD.CTESTBDD") Dim rst As ADODB.Recordset Dim requete As String requete = "INSERT INTO testdal values ('" & ligne & "')" Set rst = objBDD.FgeExecuterRequeteSimple(requete) If GetObjectContext.IsInTransaction Then GetObjectContext.SetComplete End If Exit Function GestionErreur: If GetObjectContext.IsInTransaction Then GetObjectContext.SetAbort End If End Function
Merci
Partager