jueves, 24 de abril de 2008

Método de conexión a SAP desde .net

public int Ejecutar()
{
Destination r3 = _fnDefineConexion();
// Se cargan los parámetros de entrada en una tabla.
Z_PARAM2Table _sapTablaParam = null;
_sapTablaParam = new Z_PARAM2Table ();
Z_PARAM2 Entrada = null;
Entrada = new Z_PARAM ();
Entrada.Valor1 = Valor1;
Entrada.Valor2 = Valor2;
Entrada.Valor3 = Valor3;
_sapTablaParam.Add(Entrada);
Entrada = null;
ReportesSAP rfc = null;
// Se ejecuta el RFC
rfc = new ReportesSAP(r3.ConnectionString);
rfc.Z_Historia(ref _sapTabla,
ref _sapTablaMsgError,
ref _sapTablaParam);
rfc.Connection.Close();
rfc.Dispose();
rfc = null;
r3.Dispose();
r3 = null;
return 0;
}
----------------------
//Función para la definición del string de conexión.
private Destination _fnDefineConexion()
{
Destination r3 = new Destination();
if (ConfigurationSettings.AppSettings["UserName"].Length > 0 )
{
r3.Username = ConfigurationSettings.AppSettings["UserName"];
}
if (ConfigurationSettings.AppSettings["Password"].Length > 0 )
{
r3.Password = ConfigurationSettings.AppSettings["Password"];
}
if (ConfigurationSettings.AppSettings["Client"].Length > 0 )
{
r3.Client =Convert.ToInt16(ConfigurationSettings.AppSettings["Client"].ToString());
}
if (ConfigurationSettings.AppSettings["SystemNumber"].Length > 0 )
{
r3.SystemNumber =Convert.ToInt16(ConfigurationSettings.AppSettings["SystemNumber"].ToString());
}
if (ConfigurationSettings.AppSettings["LogonGroup"].Length > 0 )
{
r3.LogonGroup =ConfigurationSettings.AppSettings["LogonGroup"];
}
if (ConfigurationSettings.AppSettings["SAPSystemName"].Length > 0 )
{
r3.SAPSystemName =ConfigurationSettings.AppSettings["SAPSystemName"];
}
if (ConfigurationSettings.AppSettings["AppServerHost"].Length > 0 )
{
r3.AppServerHost =ConfigurationSettings.AppSettings["AppServerHost"];
}
return r3;
}
--------------------------

Variables de conexión en el web.config

<add key="Username" value=""/>
<add key="Password" value=""/>
<add key="Client" value="100"/> <!-- Ambiente!-->
<add key="SystemNumber" value="00"/> <!-- Número sistema -->
<add key="AppServerHost" value="10.10.10.1"/> <!-- IP Server -->
<add key="MsgServerHost" value=""/>
<add key="LogonGroup" value=""/>
<add key="SAPSystemName" value=""/>

No hay comentarios:

Búsqueda