Click here to Skip to main content
12,996,709 members (78,988 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Dear Friends,

I am using COM component from dot net to connect SAP and access one of function from SAP, for your reference i have provided my test code, for this code i am using Visual Studio 2010.

using SAPLogonCtrl;
using SAPFunctionsOCX;
Public void TestCode()
 SAPLogonCtrl.Connection SapConnection = default(SAPLogonCtrl.Connection);
 SAPFunctionsOCX.SAPFunctions SapFns = new SAPFunctionsOCX.SAPFunctions();
 SAPLogonCtrl.SAPLogonControl SapLogonCtrl = new SAPLogonCtrl.SAPLogonControl();
 SapLogonCtrl.ApplicationServer = MyApplnServer;
 SapLogonCtrl.Client = MyClient;
 SapLogonCtrl.User = User;
 SapLogonCtrl.Password = Pwd;
 SapLogonCtrl.Language = "EN";
 SapFns.Connection = SapConnection;//<-- Getting error BAD VARIANT TYPE when using through Web Service
 SAPFunctionsOCX.Function SapFunctionInterface = default(SAPFunctionsOCX.Function);
 SapFunctionInterface = (SAPFunctionsOCX.Function)SapFns.Add(FM);

When i use through Window application all work fine but when same code used from Web Service it give me "BAD VARIANT TYPE" error (at the time of setting SapConnection to SapFns.Connection)...

Please help me regarding where i am going wrong or any link which will help me for same issue...

Thanks and Regards,
Santosh Sawant
Posted 9-Jul-13 21:48pm
Updated 9-Jul-13 21:49pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Dear Friends,


I have found the solution for the BAD VARIANT TYPE issue...

The SAP system is single thread where as when we call it we have to take care of this important requirement, when we try to connect SAP using Window application it will work cause of Single Thread created on each event but when we create Window Service it is not single threaded so we have to change the event to single thread which could be possible by explicitly make call to this method as single thread, frankly speaking i got this code after search on google (find the below url for your reference), in this url the scenario is difference but this give me direction how to explicitly do single thread.

My Code :
var staThread = new System.Threading.Thread(() => MyMethod());

This above code help the method to work as single thread and the connection is establish without any error.

Thanks Romoku for your answer in below url which help me lot.

Google URL for the example :[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170609.2 | Last Updated 19 Mar 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100