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;
names