Getting execution plan through C#


private void Form1_Load(object sender, EventArgs e)

{

string strConn = “server=Localhost;database=AMT_DB;UID=sa;PWD=”;

SqlConnection conn = new SqlConnection(strConn);

SqlDataReader reader;

conn.Open();

SqlCommand cmd = new SqlCommand();

cmd.Connection = conn;

cmd.CommandText = “SET SHOWPLAN_ALL ON”;

cmd.CommandType = CommandType.Text;

cmd.ExecuteNonQuery();

cmd.CommandText = “select * from script S inner join scriptline SL on S.scriptid=SL.scriptid”;

cmd.CommandType = CommandType.Text;

reader = cmd.ExecuteReader();

while (reader.Read())

{

MessageBox.Show(“physicalop ” + reader[4].ToString());

MessageBox.Show(“logicalop ” + reader[5].ToString());

MessageBox.Show(“argument ” + reader[6].ToString());

MessageBox.Show(“estimateio ” + reader[9].ToString());

MessageBox.Show(“estimatecpu ” +reader[10].ToString());

}

cmd.CommandText = “SET SHOWPLAN_ALL OFF”;

cmd.CommandType = CommandType.Text;

cmd.ExecuteNonQuery();

conn.close

}



Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: