1.安装sap .net connector 3.0,在C:\Program Files\SAP\SAP_DotNetConnector3_x86你会得到四个dll文件:sapnco_utils.dll sapnco.dll rscp4n.dll libicudecnumber.dll
2.使用vs2010 我们创建一个项目,添加对上面四个dll文件的引用,实际上只有三个是可以引用成功的,libicudecnumber.dll的引用会失败,注意在这里,你看上去是引用成功的,其实你后面的程序是不能运行的。这个需要你在程序属性中做一些小修改才可以:修改“项目属性”-“应用程序”-“目标框架” ,由“.NET Framework 4 Client Profile”修改为“.NET Framework 4”,最后引用 .NET 4.0 的 System.Web.dll 。只有这样sapnco.dll才可以被正常引用;否则就会提示:“SAP.Middleware.Connector.RfcConfigParameters”的类型初始值设定项引发异常。
3.using SAP.Middleware.Connector;这个不用多说
4.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication2
{
public class SAPSeverInfo
{
public string NAME { set; get; }
public string ASHOST { set; get; }
public string SYSNR { set; get; }
public string CLIENT { set; get; }
public string LANG { set; get; }
public string USER { set; get; }
public string PASSWD { set; get; }
public string Type { set; get; }
}
}
5.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAP.Middleware.Connector;
namespace WindowsFormsApplication2
{
public class SapConfig : IDestinationConfiguration
{
#region IDestinationConfiguration 成員
private SAPSeverInfo info;
public SapConfig(SAPSeverInfo info)
{
this.info = info;
}
public RfcConfigParameters GetParameters(string destinationName)
{
try
{
if ("PRD".Equals(destinationName))
{
RfcConfigParameters parms = new RfcConfigParameters();
parms.Add(RfcConfigParameters.AppServerHost, info.ASHOST);
parms.Add(RfcConfigParameters.Client, info.CLIENT);
parms.Add(RfcConfigParameters.User, info.USER);
parms.Add(RfcConfigParameters.Password, info.PASSWD);
parms.Add(RfcConfigParameters.Language, info.LANG);
parms.Add(RfcConfigParameters.SystemNumber, info.SYSNR);
return parms;
}
else { return null; }
}
catch (Exception ex) { return null; }
}
#endregion
public bool ChangeEventsSupported()
{
return false;
}
public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;
}
}
6.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAP.Middleware.Connector;
using System.Data;
namespace WindowsFormsApplication2
{
public class SAPServerConnector : IDisposable
{
private SAPSeverInfo sapInfo = null;
private RfcDestination prd = null;

本文详细介绍了如何使用C#通过NCO3.0连接到SAP系统并调用RFC。首先,需要安装SAP .NET Connector 3.0,并确保正确引用DLL文件。然后,在VS2010项目中配置.NET Framework版本,创建SAP连接配置类,实现IDestinationConfiguration接口。接着,实例化SAP连接器,设置连接参数,并调用SAP RFC函数进行数据交互。通过示例代码展示了如何获取SAP表信息并将其转换为DataTable。
最低0.47元/天 解锁文章
1593

被折叠的 条评论
为什么被折叠?



