using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Data.Sql; namespace RPCQuery { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { DateTime t1, t2; int time=0; SqlDataReader resConsulta = null; SqlConnection conexionSQL = new SqlConnection(); conexionSQL.ConnectionString = "Server=" + textBox1.Text + ";initial catalog=" + textBox2.Text + "; Trusted_Connection=TRUE"; conexionSQL.Open(); SqlCommand cmd = new SqlCommand("dbo.sp_executesql", conexionSQL); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Statement", SqlDbType.NVarChar); cmd.Parameters["@Statement"].Value = richTextBox1.Text; t1 = DateTime.Now; resConsulta = cmd.ExecuteReader(); t2 = DateTime.Now; time = t2.Minute * 60000 + t2.Second * 1000 + t2.Millisecond - (t1.Minute * 60000 + t1.Second * 1000 + t1.Millisecond); textBox3.Text = t1.Minute + ":" + t1.Second + ":" + t1.Millisecond + " - " + t2.Minute + ":" + t2.Second + ":" + t2.Millisecond + " Diff: " + time.ToString(); resConsulta.Close(); cmd.Dispose(); conexionSQL.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
Lanzar Query por RPC
Started by Alberto Dominguez, sep 28 2011 22:05
1 reply to this topic
#1
Escrito 28 septiembre 2011 - 22:05
Dejo código de programita para lanzar queries por RPC para comprobar rendimiento de los servers de Bases de Datos desde un servidor distinto al RMS:
Saludos,
Alberto Dominguez
Enterprise Architect y Trainer
MCT, MCPD, MCITP, MCITP Dynamics, MCSE, MCSA, MCTS, MCP...
ITIL V3 Foundation Qualification in IT Service Management
Perfil Profesional Twitter
Alberto Dominguez
Enterprise Architect y Trainer
MCT, MCPD, MCITP, MCITP Dynamics, MCSE, MCSA, MCTS, MCP...
ITIL V3 Foundation Qualification in IT Service Management
Perfil Profesional Twitter
#2
Escrito 27 octubre 2011 - 04:49
IMPORTANTE DETALLE:
Comentar que el tiempo que podemos ver en una traza del evento RPC Completed, no tiene porqué ser exactamente el tiempo que tarda en realizarse la query. Mide el tiempo desde que el sistema remoto abré la conexión hasta que la cierra. Si metieramos un delay antes de cerrar la conexión en nuestro código, podríamos ver en una traza que la Duración del RPC Completed es el tiempo que nosotros fijemos en el delay + la query.
Comentar que el tiempo que podemos ver en una traza del evento RPC Completed, no tiene porqué ser exactamente el tiempo que tarda en realizarse la query. Mide el tiempo desde que el sistema remoto abré la conexión hasta que la cierra. Si metieramos un delay antes de cerrar la conexión en nuestro código, podríamos ver en una traza que la Duración del RPC Completed es el tiempo que nosotros fijemos en el delay + la query.
Saludos,
Alberto Dominguez
Enterprise Architect y Trainer
MCT, MCPD, MCITP, MCITP Dynamics, MCSE, MCSA, MCTS, MCP...
ITIL V3 Foundation Qualification in IT Service Management
Perfil Profesional Twitter
Alberto Dominguez
Enterprise Architect y Trainer
MCT, MCPD, MCITP, MCITP Dynamics, MCSE, MCSA, MCTS, MCP...
ITIL V3 Foundation Qualification in IT Service Management
Perfil Profesional Twitter
0 usuarios están leyendo este tema
0 miembro/s, 0 invitado/s, 0 usuario/s anónimo/s