Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to fetch the store procedure with details(e.g cpu usage,time etc), from front end.

e.g., IF i had a abc solution running in front end and i had running the login page in front, then i want to know which store procedure is executing in beck end .

Having any solution .

What I have tried:

C#
string Connstring = "Data Source=" + txtservername.Text + "; Initial Catalog=" + txtLDatabase.Text + "; Persist Security Info=true; User ID=" + txtLUName.Text + "; Password=" + txtLPassword.Text + ";Connect Timeout=0";
            //"Data Source=" + txtservername.Text + "; Initial Catalog=" + txtLDatabase.Text + "; Persist Security Info=true; User ID=" + txtLUName.Text + "; Password=" + txtLPassword.Text + ";Connect Timeout=0";
            SqlConnection cn = new SqlConnection(Connstring);
            try
            {
                cn.Open();
                SqlCommand cmd = new SqlCommand("SELECT * FROM sys.Databases WHERE state = 0", cn);
                SqlDataAdapter adp = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                cmd.CommandTimeout = 0;
                adp.Fill(ds);
                cmd.Dispose();
                cmd = new SqlCommand("SELECT * FROM  master..sysprocesses WHERE spid > 50", cn);
                DataSet ds1 = new DataSet();
                SqlDataAdapter adp1 = new SqlDataAdapter(cmd);
                adp1.Fill(ds1);
                string str = cmd.ExecuteScalar().ToString();
                if (ds.Tables[0].Rows.Count != 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        ddlPublisherServer.Items.Add(ds.Tables[0].Rows[i][0]);

                    //dataGridView1.DataSource = ds.Tables[0];
                    dataGridView1.DataSource = ds.Tables[0];                 
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid User Name or Password" + ex.Message);
            }
Posted
Updated 6-Dec-16 22:31pm

Hi,

You mean to track activity

You need to maintain track in separate table call 'ActivityLog' in that you need to add each and every activity information(like insert city,store procedure name,access time,access by whom) you performed.

If you want to store data using store procedure then there will be no automatically call. You have to create store procedure then call that stored procedure in c#. CommandType.StoreProcedure.


Hope You got solution from this.
 
Share this answer
 
Hi,

Can you please more detail about your question with precise example ?

you are trying to connect sql sever from your given User Interface. Are you trying to know what exact store procedure run when SQL server connect ?
 
Share this answer
 
Comments
JaspalSingh03 7-Dec-16 3:57am    
actually i want to store current runnable stored procedure in database.

suppose.,we are running any dynamic project,and inserting any City or State master Page,
in such case the store procedure in background will call i.e insertcity,or whatever.
and whatever process running in front side ,all the procedure will automatically updated in database.

I want to show in front end side and want to store in database.

Hope You will get my question.
Er Parul 7-Dec-16 4:34am    
Hi,

You mean to track activity

You need to maintain track in separate table call 'ActivityLog' in that you need to add each and every activity information(like insert city,store procedure name,access time,access by whom) you performed.

If you want to store data using store procedure then there will be no automatically call. You have to create store procedure then call that stored procedure in c#. CommandType.StoreProcedure.


Hope You got solution from this.
JaspalSingh03 7-Dec-16 5:45am    
some how i got the idea from your suggestion.
But how to get exactly the stored procedure name ,when we run the front end solution forms.
(e.g.. I am running the citymaster form from front end ,and the log will detect which query is taken place .)
Er Parul 7-Dec-16 6:24am    
Hi,

If you will get proper solution or even hint from given solution than please don't give rate down like one star as its decrease profile point who given the solution of question.
Er Parul 7-Dec-16 6:31am    
Hi,

Its logical whenever you perform insert or update of your citymaster at that time you have to create log for that activity whether its insert or update or delete its obivious that you can get storeprocedure name easily :)

example. Here I am doing using storeprocedure itself but you can do same at c# side as well

CREATE STOREProcedure INSERTCITY
(
@CiTYNAME VARCHAR(50)
)
BEGIN

INSERT INTO CITY VALUES(........)

//Log activity
INSERT INTO ActivityLOG Values(.........)

END





This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900