How can I execute an SP with the functions of Command and Entity Developers

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
qmascore
Posts: 1
Joined: Tue 04 Feb 2020 04:11

How can I execute an SP with the functions of Command and Entity Developers

Post by qmascore » Tue 04 Feb 2020 04:35

Good night, I am trying to call an SP using the command instructions, but this gives me an error on the first line to initialize the connection, I leave my code that I have, I am working with WindowsForm and C #.

Code: Select all

public static string mpxGeneraCodigoCliente(string pcMaximoCodigo, int pnIdEmpresa)
        {
            // Declaracion de Variables que retornaran el resultado del sp
            string acReturnProximoCodigo = string.Empty;
            string acReturnPrefijo = string.Empty;
            string acReturnMaximo = string.Empty;
            // Capturar la Excepción del mensaje del error.
            try
            {
                // Realizar la cadena de conexion'C00181'           "DXAClientes.Properties.Settings.mCnxSIAFCORE"
                //using (EntityConnection entityConnection = new EntityConnection("name=SIAFCOREEntities"))
                using (EntityConnection entityConnection = new EntityConnection(@"name=mCnxSIAFCORE"))
                {
                    // Habrir la conexion con el servidor servidor
                    entityConnection.Open();

                    EntityCommand cmdEntityCommand = entityConnection.CreateCommand();
                    cmdEntityCommand.CommandText = "CNF.mpxMaxCodEntGet";
                    cmdEntityCommand.CommandType = CommandType.StoredProcedure;
                    cmdEntityCommand.CommandTimeout = 0;

                    // Configurar los parametros del SP Command
                    EntityParameter pnIDECIA = new EntityParameter();
                    EntityParameter pcMascara = new EntityParameter();
                    EntityParameter pnLongitud = new EntityParameter();
                    EntityParameter pnvalor_consecutivo = new EntityParameter();
                    EntityParameter pcEsquema_Tabla = new EntityParameter();

                    // Asignando los valores a los parametros
                    pnIDECIA.Value = pnIdEmpresa;
                    pcMascara.Value = "C99999";
                    pnLongitud.Value = 6;
                    pnvalor_consecutivo.Value = pcMaximoCodigo;
                    pcEsquema_Tabla.Value = "CLI.MSTCLI";

                    // Asignando los nombres a los parametros
                    pnIDECIA.ParameterName = "@pnIDECIA";
                    pcMascara.ParameterName = "@pcMascara";
                    pnLongitud.ParameterName = "@pnLongitud";
                    pnvalor_consecutivo.ParameterName = "@pnvalor_consecutivo";
                    pcEsquema_Tabla.ParameterName = "@CLI.MSTCLI";

                    // Agregar los parametros a la fuente de datos
                    cmdEntityCommand.Parameters.Add(pnIDECIA);
                    cmdEntityCommand.Parameters.Add(pcMascara);
                    cmdEntityCommand.Parameters.Add(pnLongitud);
                    cmdEntityCommand.Parameters.Add(pnvalor_consecutivo);
                    cmdEntityCommand.Parameters.Add(pcEsquema_Tabla);

                    // Execute the Command. // Executar el command del Activo fija.
                    using (EntityDataReader aoEDR = cmdEntityCommand.ExecuteReader(CommandBehavior.SequentialAccess))
                    {
                        // Read the results returned  by the store procedure
                        // Leer el resultado del SP y retonar el valor
                        while (aoEDR.Read())
                        {
                            acReturnPrefijo = aoEDR["Prefijo"].ToString();
                            acReturnMaximo = aoEDR["Maximo"].ToString();
                        }
                    }
                }
            }
            catch (System.Data.EntityException Ex)
            {
                XtraMessageBox.Show(Ex.ToString(), "Error - EF en Cliente", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.ToString(), "Error - Codigo de Cliente", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            // armo el codigo generado o devuelto por el SP para retonarlo al control
            acReturnProximoCodigo = acReturnPrefijo.Trim() + acReturnMaximo.Trim();
            // Retorna el nuevo codigo del empleado
            return acReturnProximoCodigo.ToString().Trim();
        }
When I do using the Entity conection it tells me that the context is not valid or to be more specific the error:
The connection with the specified name is not found in the configuration, is not appropriate for use with the EntityClient provider, or is not valid.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: How can I execute an SP with the functions of Command and Entity Developers

Post by Shalex » Mon 10 Feb 2020 19:17

We have asked for additional information by email.

Post Reply