Click here to Skip to main content
Click here to Skip to main content

Connection to SAP from Visual Studio 2008 with SAP.NET Connector 2.0

By , 24 Apr 2009
 

Introduction

SAP is an inalienable system for large enterprise firms. We have to connect to this system if we need some data that belongs to SAP. The platforms can be Visual Studio 2008, Visual Studio 2005, Eclipse, or any other development tool.

But, there is a problem when connecting to SAP with Visual Studio 2008. The problem is SAP does not have a connector for Visual Studio 2005 and Visual Studio 2008. Up to Visual Studio .NET 2003 platform, there were no problems about connections to SAP.

As I mentioned in my other articles, the reason there is no connector for Visual Studio 2005 and Visual Studio 2008 is primarily marketing strategies. Let's not think why SAP did not make available an add-on for Visual Studio 2008, but think how can we solve this problem with available technologies.

Prerequisite Technologies

  • Visual Studio .NET 2003
  • Visual Studio 2008
  • SAP.NET Connector 2.0
  • Any SAP Application Server

Before reading this article, I suggest reading this article.

Using the Code

As I mentioned above, we will first use Visual Studio .NET 2003. Our purpose is to connect to SAP with Visual Studio 2003. While operating, we will create a class library project. Then, we will give a reference to this application to Visual Studio 2008. Thus, the problem about connection to SAP with Visual Studio 2008 will be solved. Meanwhile, this solution is recommended by SAP.

Let's start creating a class library project first.

sap_conn_vis2008_1.jpg

After creating the class library project, we will need to create a SAP Connector Proxy item as shown below.

sap_conn_vis2008_2.jpg

Because we will make a connection to SAP, we have to look at the SAP Servers under the Server Explorer section. We will use one of the BAPIs of SAP’s user information. This is the general view of the BOR objects:.

sap_conn_vis2008_3.jpg

We will use the ‘GetDetail’ method of the USER object. Drag and drop this method onto the SAPProxy1.sapwsdl file. Later on, there is no need for another class in our project. I am deleting the Class1.cs file.

sap_conn_vis2008_5.jpg

We have now completed the operations in the Visual Studio .NET 2003 side. You should now build your project. The output ‘SAPUserDetailComponent.dll’ will be a required file while connecting to SAP in Visual Studio 2008.

Now, we will create a Windows project under Visual Studio 2008.

sap_conn_vis2008_6.jpg

Before adding the DLL file of the previous project, we should add two more DLLs to our project. First, copy ‘SAPUserDetailComponent.dll’ to your project folder. Then, go to “..\Program Files\SAP\SAP .NET Connector 2.0″ and copy “SAP.Connector.dll” and “SAP.Connector.Rfc.dll” to your project folder.

sap_conn_vis2008_7.jpg

sap_conn_vis2008_9.jpg

We should pay attention to another point. The SAP Proxy is based on the SOAP protocol. So, we need to add the “System.Web.Services” DLL to our references.

sap_conn_vis2008_10.jpg

I have only added simple controls into Form1. The logic is simple, a SAP username will be taken, and the profiles authorization of this user will be printed into a table to show. Form1 will look as shown below.

sap_conn_vis2008_11.jpg

First, I inform the Visual Studio builder about the usage of the SAPUserDetailComponent assembly file:

using SAPUserDetailComponent;

Then, I write the code for the GetProfiles button’s Click event.

SAPProxy1 proxy = new SAPProxy1();

The SAPProxy1 class is referenced in our SAPUserDetail component reference.

BAPIADDR3 address = new BAPIADDR3();
BAPIUSCOMP companyName = new BAPIUSCOMP();
BAPIDEFAUL defaults = new BAPIDEFAUL();
BAPILOGOND logonData = new BAPILOGOND();
BAPISNCU snc = new BAPISNCU();
BAPIAGRTable activeGroups = new BAPIAGRTable();
BAPICOMREMTable addcomrem = new BAPICOMREMTable();
BAPIADFAXTable addfax = new BAPIADFAXTable();
BAPIADPAGTable addpag = new BAPIADPAGTable();
BAPIADPRTTable addprt = new BAPIADPRTTable();
BAPIADRFCTable addrfc = new BAPIADRFCTable();
BAPIADRMLTable addrml = new BAPIADRMLTable();
BAPIADSMTPTable addsmtp = new BAPIADSMTPTable();
BAPIADSSFTable addssf = new BAPIADSSFTable();
BAPIADTELTable addtel = new BAPIADTELTable();
BAPIADTLXTable addtlx = new BAPIADTLXTable();
BAPIADTTXTable addttx = new BAPIADTTXTable();
BAPIADURITable adduri = new BAPIADURITable();
BAPIADX400Table addx400 = new BAPIADX400Table();
BAPIPARAMTable parameter = new BAPIPARAMTable();
BAPIPROFTable profiles = new BAPIPROFTable();
BAPIRET2Table return0 = new BAPIRET2Table();

The above variables will be used while calling the SAP function.

SAP.Connector.Destination destination = new SAP.Connector.Destination();

We need to create a destination object to connect SAP. Later on, we will set the properties of this destination object as I have shown below.

destination.AppServerHost = YOUR HOST NAME OR IP
destination.Client = YOUR CLIENT NUMBER
destination.Password = USER'S PASSWORD
destination.SystemNumber = SYSTEM NUMBER
destination.Username = USER'S NAME

Our destination object will be a parameter for the SAPConnection class.

SAP.Connector.SAPConnection connection = 
   new SAP.Connector.SAPConnection(destination);

And, our connection object will be assigned to the proxy object.

proxy.Connection = connection;

Now, we open the connection.

proxy.Connection.Open();

Call the SAP function:

proxy.Bapi_User_Get_Detail(tbUsername.Text.Trim(), out address, out companyName, 
   out defaults, out logonData, out snc, ref activeGroups, 
   ref addcomrem, ref addfax, ref addpag, ref addprt, ref addrfc, 
   ref addrml, ref addsmtp, ref addssf, ref addtel, ref addtlx, 
   ref addttx, ref adduri, ref addx400, 
   ref parameter, ref profiles, ref return0);

Then, close the connection.

proxy.Connection.Close();

And, I will convert the result table of this function to an ADO table as I have shown below:

DataTable dt = profiles.ToADODataTable();

The last operation is we give the data table as a source for the grid view.

dgProfiles.DataSource = dt; 

The result screen will be:

sap_conn_vis2008_12.jpg

You can also visit my technical blog site for my other articles.

License

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

About the Author

huseyinakturk
Software Developer (Senior)
Turkey Turkey
Member
Huseyin Akturk was born in Ankara, Turkey. He holds BSc degree from Dokuz Eylul University, Izmir, Turkey Computer Engineering department since July 2005. He also holds MSc degree from Ege University, Izmir, Turkey Computer Engineering department since March 2008.
 
He has applied data mining technology and statistical operations on stock exchanges during BSc and MSc theses. The purpose of these theses is looking for similarity between stock exchanges and he has got successful results in these theses respect to the purpose and published essays.
 
He has worked with a responsibility of being computer engineer during professional and academic experience. He has assimilated the idea of being keen on newness in technology. He has been working as Senior SAP Business Intelligence Consultant, Senior SAP Technical Consultant and Senior Software Engineer for several firms since October 2005.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionAn alternative .NET container from VS StudiomemberMYLES MORRIS29 Nov '11 - 13:40 
Merhaba Huseyin!
 
Thank you for your post. I work with an industrial application which supports scripting in any .NET class, simply import DLLs (e.g. system.windows.forms) and go from there.
 
Do you think it is possible for me to replicate what you have done in Vis Studio in my applicaiton by simply importing the DLLs listed in your post?
 
Cheers,
Myles Morris
GeneralSend data to SAP ZtablememberMember 231241710 Mar '11 - 19:15 
I want to add records into a Z-table provided by the client by making use of the provided BAPI for the table and its structure.
It is sort of an exporting data from my .NET C# application to SAP.
 
Any help on this will be appreciated.
 
Thanks in advance.
GeneralMy vote of 4memberMember 231241710 Mar '11 - 19:11 
Good informative article for the novices.
GeneralMy vote of 4memberRajeev Kumar2228 Dec '10 - 0:10 
very good wxample for getting data from sap server
GeneralMy vote of 3memberpealiroy2005@gmail.com19 Oct '10 - 2:42 
Need more detail about the connector
GeneralRe: My vote of 3memberhuseyinakturk19 Nov '10 - 1:40 
Thanks for your interest.
 
But, this article focus on connecting SAP Application server via Visual Studio 2005 & 2008 using SAP.NET Connector 2.0. Because of this, .NET Connector details are second importance.
GeneralError on parameters used in Bapi_User_Get_DetailmemberOmarGP22 Sep '10 - 8:29 
I'm getting the following error when I tried to run your example:
 
"No overload for method 'Bapi_User_Get_Detail' takes '23' arguments'
 
Can you help me?
GeneralPaste this with all parameters -> Error on parameters used in Bapi_User_Get_DetailmemberMember 240814027 Sep '10 - 4:46 
BAPIADDR3 address = new BAPIADDR3();
BAPIALIAS alias = new BAPIALIAS();
BAPIUSCOMP companyName = new BAPIUSCOMP();
BAPIDEFAUL defaults = new BAPIDEFAUL();
BAPISLOCKD islocked = new BAPISLOCKD();
BAPIMODDAT lastmodified = new BAPIMODDAT();
BAPILOGOND logonData = new BAPILOGOND();
BAPIREFUS ref_user = new BAPIREFUS();
BAPISNCU snc = new BAPISNCU();
BAPIUCLASS uclass = new BAPIUCLASS();
BAPIAGRTable activeGroups = new BAPIAGRTable();
BAPICOMREMTable addcomrem = new BAPICOMREMTable();
BAPIADFAXTable addfax = new BAPIADFAXTable();
BAPIADPAGTable addpag = new BAPIADPAGTable();
BAPIADPRTTable addprt = new BAPIADPRTTable();
BAPIADRFCTable addrfc = new BAPIADRFCTable();
BAPIADRMLTable addrml = new BAPIADRMLTable();
BAPIADSMTPTable addsmtp = new BAPIADSMTPTable();
BAPIADSSFTable addssf = new BAPIADSSFTable();
BAPIADTELTable addtel = new BAPIADTELTable();
BAPIADTLXTable addtlx = new BAPIADTLXTable();
BAPIADTTXTable addttx = new BAPIADTTXTable();
BAPIADURITable adduri = new BAPIADURITable();
BAPIADX400Table addx400 = new BAPIADX400Table();
BAPIUSEXTIDHEADTable extidhead = new BAPIUSEXTIDHEADTable();
BAPIUSEXTIDPARTTable extidpart = new BAPIUSEXTIDPARTTable();
BAPIGROUPSTable groups = new BAPIGROUPSTable();
BAPIPARAMTable parameter = new BAPIPARAMTable();
BAPIPARAM1Table parameter1 = new BAPIPARAM1Table();
BAPIPROFTable profiles = new BAPIPROFTable();
BAPIRET2Table return0 = new BAPIRET2Table();
BAPIRCVSYSTable systems = new BAPIRCVSYSTable();
BAPIUCLASSSYSTable uclasssys = new BAPIUCLASSSYSTable();
 
proxy.Bapi_User_Get_Detail(tbUsername.Text.Trim(), out address, out alias, out companyName,
out defaults, out islocked, out lastmodified, out logonData, out ref_user, out snc, out uclass,
ref activeGroups, ref addcomrem, ref addfax, ref addpag, ref addprt, ref addrfc,
ref addrml, ref addsmtp, ref addssf, ref addtel, ref addtlx, ref addttx, ref adduri,
ref addx400, ref extidhead, ref extidpart, ref groups, ref parameter, ref parameter1,
ref profiles, ref return0, ref systems, ref uclasssys);
 
Axel Arnold Bangert - Herzogenrath 2010
Herzogenrath, Axel Arnold Bangert

GeneralRe: Paste this with all parameters -> Error on parameters used in Bapi_User_Get_DetailmemberOmarGP27 Sep '10 - 8:21 
Thank you very much. It worked fine!!
GeneralRe: Paste this with all parameters -> Error on parameters used in Bapi_User_Get_DetailmemberAshishgadekar23 Jan '13 - 17:58 
Dear Expert, i paste this code on click event, but i got same error "no overload for method bapi_user_get_detail" take "34" arguments. why am getting this. in my form i took one gridview, textbox and a button. pls suggest. Or how can i display bapi_employee_getdata in gridview.
Questiondrag and drop ok?memberOdella Chen1 Jul '10 - 20:35 
thank you very much.But i want to know whether we could use add-on in vs2008 as we do in vs2003? drag and drop is more easy and convenient.
 
thank you in advance
AnswerRe: drag and drop ok?memberhuseyinakturk21 Jul '10 - 6:02 
Hi,
 
It is not possible with standart class library usage.
 
Regards,
 
Huseyin Akturk
GeneralMy vote of 1memberIzzet Kerem Kusmezer14 Apr '10 - 3:10 
Poor
GeneralFrom .net app to sapmembersaperman9 Feb '10 - 22:24 
Hi.
 
Is it possible to make opposite connection ... connect SAP to .net application?
I mean to get data and use functions of an windows application in SAP system? ... Via .net connector?
Could you give me some advice how to do it or show some guide where I could study it?
 
Thank you in advance.
GeneralRe: From .net app to sapmemberhuseyinakturk9 Feb '10 - 22:28 
Hi,
Yes possible, you can examine my other article. It's for your desire.
 
SAP .NET RFC Server with SAP.NET Connector 2.0[^]
 
Regards,
Huseyin Akturk
http://www.huseyinakturk.net
GeneralVery helpfulmember$2008 Dec '09 - 14:57 
Many thanks to the tips. This is exactly what we are looking forThumbs Up | :thumbsup: .
 
Do you perhaps know where we can still find Visual Studio 2003? I did a search a Google and there's no luck; or if you still have the DLL files, can you include them in the article?
GeneralRe: Very helpfulmemberhuseyinakturk13 Dec '09 - 5:15 
Hi,
 
Thanks firstly,
 
You can find Visual Studio 2003 via microsoft commercial page.
 
You mentioned dll files, but is not eneough dll files, also which dll files? You have to have Visual Studio 2003 development tool.
 
Regards,
 
Huseyin Akturk
GeneralRe: Very helpfulmember$2006 Jan '10 - 17:25 
I don't think they still offer VS2003 these days, at least from what I've seen Sigh | :sigh: . Thus I was wondering if you can share the dll files generated in VS2003 from the Connector.
 
ps. I will probably go try the VS2010 Express beta later to see if it can open the connector.
 
Thanks
GeneralRe: Very helpfulmemberpeterklausen21 Feb '10 - 14:24 
There's a new tool (<a href="http://www.aconcaguait.com/explorerproxygen2008.php">http://www.aconcaguait.com/explorerproxygen2008.php</a>[<a href="http://www.aconcaguait.com/explorerproxygen2008.php" target="_blank" title="New Window">^</a>]) to evaluate. I've requested a trial (Only tried the VS2008 version). It worked just fine and has lower prices than other similar tools. The feature set seems adecuate as well (RFC documentation, code snippets, RFC Servers).
 
It also seems to be using the latest version of librfc32.dll (allowing more than 8-chars passwords, etc)
 
there's also a how-to guide....http://www.youtube.com/watch?v=72nM-vuYfFI[^]
 
worth to take a look.
 
Cheers!
 
PK.
GeneralThank you!membermthd733 Aug '09 - 11:57 
This was a wonderful article. Don't listen to earlier criticism.
 
1. Not all of us can/want to use thrid party vendor software.
2. There are those of us who are still stuck using the SAP .NET connector for 1.1 and are trying to get the most out of it.
3. Simply reading from the SAP database but not being able to write back to it would have been useless for us.
 
Thank you for this artcile and the time you took to do all the screenshots. Smile | :)
GeneralRe: Thank you!memberhuseyinakturk4 Aug '09 - 5:06 
Hi,
 
I also thank to you. Your comments and thanks encourage me. I will publish new articles. Waiting for all time to codeproject and my blog site : http://www.huseyinakturk.net
 
Regards,
 
Huseyin Akturk
QuestionVery useful and informative. Thanks. I need helpmemberViji Raj25 Jun '09 - 14:37 
Hi,
 
Your article is very informative. But i want to retrieve tables from SAP. can you explain me how to do that? This is a requirement for my project.
 
Thanks in advance.
AnswerRe: Very useful and informative. Thanks. I need helpmemberhuseyinakturk27 Jun '09 - 8:26 
Hi Viji,
You need to define an ABAP function that achieves your need. Then you should call that SAP function from Visual Studio.
 
Regards,
 
Huseyin Akturk
Generalget datamemberbymesut5 Jun '09 - 5:44 
hi
 
this good article
I'm define a rfc function.
How can I get any data on sap .
Thanks..
GeneralRe: get datamemberhuseyinakturk5 Jun '09 - 8:58 
You can examine my this article[^]
GeneralMy vote of 2memberIzzet Kerem Kusmezer28 Apr '09 - 4:02 
Already existing article from 3 years ago.
GeneralRe: My vote of 2memberhuseyinakturk29 Apr '09 - 9:44 
As I reply in your provious message:
"Yes SAP has a solution to this problem as my explanation. But this article has more explanation then that article. Also, an article in codeproject is doctorate thesis? Of course there will be smilar articles and nobody said there were no solution until I published this article. I only want to share my knowledge."
 
Thank you again for your vote. Normally, people gives point respect to the contents of articles. But again, thanks.
 
Regards.
GeneralNice but absolute samplememberIzzet Kerem Kusmezer27 Apr '09 - 23:01 
It has been a while that the connector is published about 6 years i guess Smile | :)
GeneralRe: Nice but absolute samplememberhuseyinakturk28 Apr '09 - 1:01 
Yes about 6 years. Nobody said Connector is a new technology. I could not understand why you have a comment about newness or oldness. Everybody does not know the technology when it arised. For somebody it can be new, for somebody it can be old.
 
Also, Visual Studio 2008 is a new technology. Read and examine the article and its subject and focuse what i want to explain.
GeneralRe: Nice but absolute samplememberIzzet Kerem Kusmezer28 Apr '09 - 4:15 
Yes, i am focused on what you are trying to tell, but:
1) You created the proxy classes directly from VS2003, which can be done and already shown in the following articles since 3 years , also SapDBReader is a more more usefull application then adding a reference to a compiled dll, which in case of VS2005 And VS2008 in case add reference has nothing to do with VS2008 is a new technology or not.
 
2) Softwise already provides port of this for VS2005:
http://www.softwise.com.ar/products.php
 
3) Also i gave for example a 4 stars to your RFC Server Implementation.
 
4) You didn't mentioned for example that if you deploy this application, then you must deploy the librfc32.dll also with it, because the .Net Connector is just a P\Invoke Wrapper around the librfc32 library, and cannot be deployed without it.
 
Also SAP has this solution also since 2006:
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/92333e6b-0b01-0010-9cbf-fecd62d6c895 and it doesn't matter if it is for 2005 or 2008, in both cases it is still a 1.1 dll.
 
Other Sap Related Articles In CodeProject:
 
http://www.codeproject.com/KB/database/SapDBReader.aspx
http://www.codeproject.com/KB/dotnet/SAP_NET_Connector.aspx
http://www.codeproject.com/KB/mobile/SAP_connector_for_NET.aspx
http://www.codeproject.com/KB/aspnet/Connecting_DotNet_and_SAP.aspx
GeneralRe: Nice but absolute samplememberhuseyinakturk29 Apr '09 - 9:38 
Hi again,
I don't want to discuss with a man who comments unfairly. But, in order to find out the truth, i will give answer.
 
Firstfull, thank you for interest to my article. My numbered answers for your numbered ideas:
1. SAPDbReader is a good solution but not a complete solution for connection to SAP with Visual Studio 2005 or with Visual Studio 2008. There is a dll and you are using that dll, and also let's try to use calling a function with this solution? You will see that this solution is valid with data read. But you can not use this solution update SAP table data. And there are bapis of SAP. Of course you can not use this solution calling this bapi. Please, examine the SAP.NET connector's mission. It is not only used reading data!
 
2. You mentioned that you can use softwise. Of course you can use another THIRD PARTY solutions to connect SAP. But, please focus that this solution with SAP.NET Connector. SAP.NET Connector is produced by SAP AG. And some developer's firms may not to use third party solutions.
 
3. Thank you for your stars.
 
4. Nobody said that you are deploying this solution with another machine. This is only for demo and shows the basic important points. But again, thank you for your contribution.
 
Yes SAP has a solution to this problem as my explanation. But this article has more explanation then that article. Also, an article in codeproject is doctorate thesis? Of course there will be smilar articles and nobody said there were no solution until I published this article. I only want to share my knowledge.
 
And, I see that one of codeproject member has a thank for my article. That is important for me. Other unfairly comments are not important for me. You can take help with this article or not. That is not important for me. I only want to help people.
 
I will not give answer like this comments. If you face with technical problem, I want to help you if I can.
 
Regards,
 
Huseyin Akturk
Generalthanks..memberJuraj Suchan24 Apr '09 - 20:54 
this should be very useful for me, thanks!
 
VirtualVoid.NET

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 24 Apr 2009
Article Copyright 2009 by huseyinakturk
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid