Contents
- Introduction
- Pre-requisites
- Procedure
- Web.config 2
- User_Control.cs 2
- Fetch Data from SAP 2
- Submit the data to SAP 3
- Exceptions Expected and solution to it 4
Introduction
There can be a scenario where we need to fetch data from SAP and submit the updates to SAP using the functions given by the SAP team from the SharePoint screen.
To enable the preceding we will be writing .Net code using NCo3015_Net40_x64 MSI.
Pre-requisites
- Ensure the following ports are opened from the entore SharePoint front end and app servers to the SAP Server:
3200, 3201, 3300, 3301, 3600, 3601
- SQL port 1433 to be opened between SharePoint front end and app servers to SQL Server.
- Download SAP NCO 3.0 package (NCo3015_Net40_x64 MSI) and install it on all servers (Development, UAT, Production [Front End, App, Distributed Cache and and so on (if any) servers]). Once installed, the following folder would be created and four DLL files are copied to that
C:\Program Files (x86)\SAP\SAP_DotNetConnector3_Net40_x64
Procedure
- Open Visual Studio 2012.
- Create an Empty SharePoint Project.
- Add a User Control then call the user control in the Visual Web Part.
- Copy the four DLL files from C:\Program Files (x86)\SAP\SAP_DotNetConnector3_Net40_x64 to the application's bin folder (C:\inetpub\wwwroot\wss\Virtualdirectories\<Port Number>\bin).
- Add a reference of sapnco.dll and sapnco_utils.dll to the project from the bin folder.
- Write code in the User Control. The following code will only connect to SAP and fetch/submit the data. No Business logic is covered here.
- Deploy / Public the WSP file on the App server (or respective server) and web application.
Web config
Add the following entry in the appsettings of the web.config file location at the application bin folder (C:\inetpub\wwwroot\wss\Virtualdirectories\<Port Number>\web.config).
Note: For production, these entries are required on all Front End server's web.config file.
- <add key="SAPIP" value="XX.XXX.XX.XX" />
- <add key="SAPUSERID" value="XXXX" />
- <add key="SAPPWD" value="XXXX" />
- <add key="SYSTEMNO" value="XX" />
User_control.cs
Fetch data from SAP
-
- RfcConfigParameters rfc = new RfcConfigParameters();
- rfc.Add(RfcConfigParameters.Name, "mySapName");
- rfc.Add(RfcConfigParameters.AppServerHost, ConfigurationManager.AppSettings["SAPIP"].ToString());
- rfc.Add(RfcConfigParameters.Client, "700");
- rfc.Add(RfcConfigParameters.User, ConfigurationManager.AppSettings["SAPUSERID"].ToString());
- rfc.Add(RfcConfigParameters.Password, ConfigurationManager.AppSettings["SAPPWD"].ToString());
- rfc.Add(RfcConfigParameters.SystemNumber, ConfigurationManager.AppSettings["SYSTEMNO"].ToString());
- rfc.Add(RfcConfigParameters.Language, "EN");
- rfc.Add(RfcConfigParameters.PoolSize, "5");
- rfc.Add(RfcConfigParameters.PeakConnectionsLimit, "10");
- rfc.Add(RfcConfigParameters.ConnectionIdleTimeout, "500");
-
-
- RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfc);
- RfcRepository rfcRep = rfcDest.Repository;
- IRfcFunction function = rfcRep.CreateFunction("<<SAP Function Name>>");
-
-
- IRfcTable UserInfo = function.GetTable("<<SAP Table to Read>>");
-
-
- function.SetValue("Field1", txtTextBox.ValidationDate);
- function.SetValue("Field2", Page.Request.QueryString["xxx"].ToString());
- function.SetValue("Field3", txtTextBox3.Text.ToString());
-
-
- function.Invoke(rfcDest);
-
Submit the data to SAP
- RfcConfigParameters rfc = new RfcConfigParameters();
- rfc.Add(RfcConfigParameters.Name, "mySapName");
- rfc.Add(RfcConfigParameters.AppServerHost, ConfigurationManager.AppSettings["SAPIP"].ToString());
- rfc.Add(RfcConfigParameters.Client, "700");
- rfc.Add(RfcConfigParameters.User, ConfigurationManager.AppSettings["SAPUSERID"].ToString());
- rfc.Add(RfcConfigParameters.Password, ConfigurationManager.AppSettings["SAPPWD"].ToString());
- rfc.Add(RfcConfigParameters.SystemNumber, ConfigurationManager.AppSettings["SYSTEMNO"].ToString());
- rfc.Add(RfcConfigParameters.Language, "EN");
- rfc.Add(RfcConfigParameters.PoolSize, "5");
- rfc.Add(RfcConfigParameters.PeakConnectionsLimit, "10");
- rfc.Add(RfcConfigParameters.ConnectionIdleTimeout, "500");
- RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfc);
- RfcRepository rfcRep = rfcDest.Repository;
- IRfcFunction function = rfcRep.CreateFunction("<<SAP submit Function Name>>");
- IRfcTable table = function.GetTable("<<SAP Table to update>>");
-
- DataTable dtmodified = (DataTable)Session["xxxxx"];
-
- foreach (DataRow row in dtmodified.Rows)
- {
- table.Append();
- table.SetValue("field1", “Value1”);
- table.SetValue("field2", “Value2”);
-
- table.SetValue("field_n", “Value_n”);
- }
-
- function.Invoke(rfcDest);
Exceptions expected and solution to it
- Could not load a file or assembly sapnco.dll / sapnco_utils.dll.
Solution
Ensure to copy the four DLLs from C:\Program Files (x86)\SAP\SAP_DotNetConnector3_Net40_x64 to the application bin folder (C:\inetpub\wwwroot\wss\Virtualdirectories\<Port Number>\bin).
- SharePoint 2013 layouts pages breaking with "Exception 'Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode:SubStatus:The request timed out".
Solution
Run the following Power Shell script to increase the response time.
First run the following commands to see the health of the distributed cache that includes the status.
- $SPFarm = Get-SPFarm
- $cacheClusterName = "SPDistributedCacheCluster_" + $SPFarm.Id.ToString()
- $cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local
- $cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName)
- $cacheClusterInfo
To resolve the issue, suggested to run following Power Shell commands that increase the distributed cache time out values to 10 seconds.
- $settings = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache
- $settings.ChannelOpenTimeOut =10000
- $settings.RequestTimeout=10000
- Set-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache -DistributedCacheClientSettings $settings
- $settingsverify = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache
- $settingsverify
-
- $settingsa = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache
- $settingsa.ChannelOpenTimeOut = 10000
- $settingsa.RequestTimeout=10000
- Set-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache -DistributedCacheClientSettings $settingsa
- $settingsaverify = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache
- $settingsaverify
-
- $set = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache
- $set.MaxBufferSize = 33554432
- Set-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache -DistributedCacheClientSettings $set
- Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache
-
- $set = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache
- $set.MaxBufferSize = 33554432
- Set-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache -DistributedCacheClientSettings $set
- Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache
- SAP.Middleware.Connector.RfsCommunicationException: Location CPIC (TCP/IP) on the local host with Unicode Error Partner "xx.xxx.xx.xxx:3301" not reached time. Connection timeout counter.
Solution
Ensure the following ports are opened from the Front End, App Servers to the SAP Server.
3200, 3201, 3300, 3301, 3600, 3601