internal static DataTable ListenAgent(MSAgent Agent) { SqlCommand command = new SqlCommand(); if (Agent.parameters.Count == 0) { command.CommandText = Agent.query; Agent.built_query = Agent.query; } else { Agent.built_query = Util.BuildQuery(Agent.query, Agent.parameters); command.CommandType = CommandType.StoredProcedure; command.CommandText = Agent.query; //CARGA LOS PARAMETROS foreach (Parameter par in Agent.parameters) { command.Parameters.AddWithValue(par.name, par.value); } //DECLARA LOS PARAMETROS DE SALIDA, SI LOS TUVIESE foreach (OuterParameter o_par in Agent.outer_parameters) { if (o_par.size == 0) { command.Parameters.Add(o_par.name, o_par.type); } else { command.Parameters.Add(o_par.name, o_par.type, o_par.size); } command.Parameters[o_par.name].Direction = ParameterDirection.Output; } } DataTable result; if (Agent.handding_transaction) { result = CommonServices.ExecuteQuery(command, Agent.connection, Agent.transaction); } else { result = CommonServices.ExecuteQuery(command, Agent.chain); } //ASIGNA LOS VALORES A LOS PARAMETROS DE SALIDA foreach (OuterParameter o_par in Agent.outer_parameters) { o_par.value = command.Parameters[o_par.name].Value; } return(result); }
/// <summary> /// ATIENDE AL AGENTE PARA UNA CARGA MASIVA DE DATOS /// </summary> /// <param name="Agent"></param> /// <returns></returns> internal static string ListenBulkAgent(MSAgent Agent) { SqlTransaction transac; SqlConnection con; con = new SqlConnection(); con.ConnectionString = Agent.chain; con.Open(); transac = con.BeginTransaction(); try { SqlBulkCopy sqlbulkcopy = new SqlBulkCopy(con, SqlBulkCopyOptions.Default, transac); sqlbulkcopy.DestinationTableName = Agent.bulk_name; sqlbulkcopy.WriteToServer(Agent.bulk_table); transac.Commit(); return("success"); } catch (Exception ex) { transac.Rollback(); con.Close(); return(ex.Message); } }
static void Main(string[] args) { //string ifx = @"Server=ecodes;Host=192.168.200.143;Service=9090;Protocol=onsoctcp;database=sfi021_ebca;User ID=nlsis010; Password=Sfi-2013;Persist Security Info=True;"; //IFXAgent agent_ifx = new IFXAgent(ifx, "informix.sp_cmovil_cargos"); //agent_ifx.BeginTransaction(); //try //{ // agent_ifx.AddParameter("i_tipo", 2); // agent_ifx.AddParameter("i_parametro", "2036681"); // //agent_ifx.AddOuterParameter("o_npre", IfxType.Integer); // agent_ifx.Execute<DataTable>(); // agent_ifx.Commit(); //} //catch (Exception ex) //{ // agent_ifx.RollBack(); //} //finally //{ // agent_ifx.CloseConnection(); //} //string ifx = "Server=dbs01;Host=192.168.200.142;Service=1527;Protocol=onsoctcp;database=sfi021;User ID=ecoprod1; Password=ecoprod1db;Persist Security Info=True;"; string chain = @"Server=171.3.0.38\data2;Initial Catalog=usuarios; Persist Security Info=True;uid=sa;pwd=Ecofuturo12;Connect Timeout=200; pooling='true'; Max Pool Size=200;"; MSAgent agent_normal = new MSAgent(chain, "usuarios..sp_usuario_web_service"); agent_normal.AddParameter("i_accion1", "S1"); agent_normal.Execute(); Console.WriteLine(agent_normal.json); //Console.ReadKey(); ////agent.AddParameter("i_accion", "S1"); //SqlTransaction trans; //SqlConnection con = new SqlConnection(chain); //con.Open(); //trans = con.BeginTransaction(); //MSAgent agent = new MSAgent("usuarios..sp_usuario_web_service", con, trans); //try //{ // //string table = // agent.AddParameter("i_accion", "S1"); // DataTable tab1 = agent.Execute<DataTable>(); // agent.parameters.Clear(); // agent.AddParameter("i_accion", "S2"); // DataTable tab2 = agent.Execute<DataTable>(); // Console.WriteLine(" "); //} //catch (Exception ex) //{ // trans.Rollback(); //} //finally{ // con.Close(); //} //MSAgent tagent = new MSAgent(chain, "usuarios..sp_usuario_web_service"); //tagent.BeginTransaction(); //try //{ // tagent.AddParameter("i_accion", "S1"); // DataTable tab1 = tagent.Execute<DataTable>(); // tagent.parameters.Clear(); // tagent.AddParameter("i_accion", "S2"); // DataTable tab2 = tagent.Execute<DataTable>(); // tagent.Commit(); //} //catch (Exception) //{ // tagent.RollBack(); //} //finally //{ // tagent.CloseConnection(); //} //if (agent.Execute() == "success") //{ // return agent.json; //} //else // return agent.error; //try //{ // grid.DataSource = agent.Execute<DataTable>("json"); //} //catch (Exception ex) //{ // Console.WriteLine(ex.Message); //} //string filename = string.Format(@"{0}\{1}", // System.IO.Path.GetTempPath(), // "testhtm.htm"); //File.WriteAllText(filename, "<h1>Hello HTT</h1>"); //Process.Start(filename); //MSAgent agent = new MSAgent(chain,"select * from usuarios..t_usuario"); //try //{ // string json = agent.Execute<string>("json"); // Console.ReadKey(); //} //catch (Exception ex) //{ // Console.WriteLine(ex.Message); // Console.ReadKey(); //} //DataTable mytable = new DataTable(); //MSAgent agent = new MSAgent(chain, "usuarios..sp_usuario_web_service"); //agent.AddParameter("i_accion", "P1"); //agent.AddParameter("i_nombre", "co"); //agent.AddOuterParameter("o_salida", SqlDbType.Int); //agent.AddOuterParameter("o_salidachar", SqlDbType.VarChar, 50); //agent.Execute(); //Response.Write(agent.json); //grid.DataSource = agent.table; //int id = int.Parse(agent.GetOuterParameter("o_salida").value); //string query = agent.built_query; //agent.GetTable(); //Console.WriteLine(agent.GetJson()); //MSAgent agent = new MSAgent(chain, "select * from usuarios..t_usuario"); //agent.Execute(); //agent.GetTable(); //IFXAgent ifxagent = new IFXAgent(ifx, "select * from sisev"); ////ifxagent.Execute(); ////Console.Write(ifxagent.json); ////Console.ReadKey(); ////MSAgent agent = new MSAgent(); ////MSAgent agent = new MSAgent(chain, "select * from usuarios..t_usuario"); ////agent.Execute(); ////Console.WriteLine(agent.json); ////Console.ReadKey(); ////MyAgent myagent = new MyAgent("Data Source=localhost;port=3306;Initial Catalog=postulaciones;User Id=root;password="******"select * from t_agencia"); ////myagent.Execute(); //MSAgent agent = new MSAgent(chain, "usuarios..sp_usuario_web_service"); //agent.AddParameter("i_accion", "P1"); //agent.AddParameter("i_nombre", "co"); //agent.AddParameter("i_numero", 1); ////agent.AddParameter("i_fecha", DateTime.Now); //agent.AddOuterParameter("o_salida", SqlDbType.Int); //agent.AddOuterParameter("o_salidachar", SqlDbType.VarChar, 50); //agent.Execute(); //string chain = @"Server=171.3.0.38\data2;Initial Catalog=usuarios; Persist Security Info=True;uid=sa;pwd=Ecofuturo12;Connect Timeout=200; pooling='true'; Max Pool Size=200;"; //MSAgent agent = new MSAgent(); //agent.chain = chain; //agent.bulk_table = mytable; //agent.bulk_name = "usuarios.dbo.t_usuario"; //string result = agent.ExecuteBulk(); //Console.WriteLine(agent.GetOuterParameter("o_salidachar").GetName()); //Console.WriteLine(agent.GetOuterParameter("o_salidachar").GetValue()); //Console.WriteLine(); //Console.WriteLine(agent.json); //Console.ReadKey(); //Console.WriteLine(agent.json); //Console.ReadKey(); }