cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting to SAP through VB.Net 2010

thomas_brutigam2
Active Participant
0 Kudos

For some Circumstances I have to switch from VBA / VB6 to VB.NET-

So since 2 Days I am Trying to Convert my Codings.

Only thing thats left is the Connection to SAP

So far i have done it
Currently looks like this:

Module:

Public SapApplication as Object

Public SapGuiAuto as Object

Public SApSession as Object

Public SApConnection as Object


Now i want to Create a "global" connection - so far its working-

If Not isReference(SapApplication) Then

     SapGuiAuto = GetObject("SAPGUI")

     SapApplication = SapGuiAuto.GetScriptingEngine

End if

Thats simply enough for Writing and Reading Values from SAP

but Somtimes i need the session - for Information about Program and Transaction-

So i create the Session in a single Sub - proof the values and close the Session -

but the "barberpole" in the right corner won't stop spinning ? (like it used to do in VB 6 / VBA)

For certain Reasons i cant use the Connector mentioned in other threads 😞

So - what is the "right" way  to Connect for the Session ?!

cheers

Thomas

Accepted Solutions (1)

Accepted Solutions (1)

holger_khn
Contributor
0 Kudos

Hi Thomas.

You need to clear the variable.

Set Session = Nothing

Then your session is released. This happen when you use gloal variables. Local variables (in a procedure) will release automatically when 'End Sub' is reached.

Br, Holger

thomas_brutigam2
Active Participant
0 Kudos

Hi Holger,

"Set" is no more longer available in .Net since VB 2008( .Net 2.5 i think)

Objects are being "Disposed" but if I am trying that i run into an Error-

I think i have to put it in a Class so i can take care of that ...

greetgs

Thomas

holger_khn
Contributor
0 Kudos

Hello.

Yes, 'Set' is no longer available. But an short statement like

Session = Nothing

should clear the variable.

Have you tried this?

Br, Holger

thomas_brutigam2
Active Participant
0 Kudos

of course 😉

otherwise I wouldnt ask ...


Gonna find out this afternoon while I am at work 🙂

Br,

Thomas

holger_khn
Contributor
0 Kudos

Ok 🙂

Without seeing your code it´s hard to say more for me as my experience in vb.net is limited. Create an class should work as this will clear objects after call.

But there must be another way as well.

thomas_brutigam2
Active Participant
0 Kudos

Hello Holger, and all others ...

this is getting me freaking out...

there is seamly no way to get this thing to work correct...

If i put the session in a Private Variable and an Extern Function (like this)

Public Function GetTransaction_Programm () as String

     Dim SapSession as Object

          SapSession = SapConnection.Children(0)
               With sapSession

                    t1 = .Info.Transaction
                    t2 = .Info.Program

               end with

          Dim Sapsession  = Nothing 'doesnt matter,....
          GetTransaction_Program = t1& "|" & t2

End Function

it should work - at least in VBA and VB 6 it worked ...

not in VB.Net
It doesnt matter how its put - the session is always terminated (so i could find out ) - but the "Scripting-sign" is still alive ?!?!

It disappears only if The Exe is Terminated ... ?

Br

Thomas

holger_khn
Contributor
0 Kudos

Hello Thomas.

Have you set anywhere gc.collect() to free memory of this object after Sapsession = Nothing or dispose this object (class?)?

Sounds like your issue is caused by this object as it is still active from memory. When exe is killed memory is cleared as well.

Br, Holger

Message was edited by: Holger Köhn (grammar issue)

thomas_brutigam2
Active Participant
0 Kudos

Hello Holger,

So far I can give "Entwarnung" ...

gc.Collect is doing nothing like expected...


Tried Compilersettings "Release" and it works 😉
aint that funny ?! *grrrrr*

br

Thomas
Solved 😉

holger_khn
Contributor
0 Kudos

Interesting. Seems like I need to develop myself and walk into VB.NET jungle. That sounds like I will feel like home 🙂

Great to hear that you find the way. DOTNET sounds like a lot of fun. Br, Holger

thomas_brutigam2
Active Participant
0 Kudos

Holger Köhn wrote:

Interesting. Seems like I need to develop myself and walk into VB.NET jungle. That sounds like I will feel like home 🙂

Great to hear that you find the way. DOTNET sounds like a lot of fun. Br, Holger

You bet ...

Its nothing like before in VB(6) or vba ...
its a complete new Universe -

To me VB(6) was more comfortable as to make a little helper (some quick n dirty ....) was faster done as in .NET but it has some Things you didnt have in the old VB ...

If you want to try you can download the newest Express Versions (2012 - dont get shocked about the IDE ... (its already Windows8 Design....*yuck*))

br

Thomas

Answers (2)

Answers (2)

thomas_brutigam2
Active Participant
0 Kudos

Finally I found a solution to the Problem-

        Try

            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)

            obj = Nothing

        Catch ex As Exception

            obj = Nothing

        Finally

            GC.Collect()

        End Try

This works like a Charm ....

Former Member
0 Kudos

Hi,

I also have the same issue of barber pole running at the bottom on the SAP screen . Could you please give a hint of how to modify the settings of release in VB express 2013.

Thanks,

stefan_schnell
Active Contributor
0 Kudos

Hello Sampath,

you can find a solution here.

Cheers

Stefan