Solved

How to get progress of  sql query using ADO.Net

Posted on 2007-11-13
7
2,166 Views
Last Modified: 2012-06-27
Hello,

Is it possible to use ADO.Net to get the progress (ie % complete) of a sql query?

The query I am running is to backup a database
eg "backup database test to disk = 'D:\mssql\backup\test.bck'

As some backup/restores take considerable time, I wish to display some progress, but don't know how to go about getting sql progress information from the sqlcommand object.

I know its possible to get the progress using other .net libraries such as SMO, but I wish to restrict the usage to only ADO.Net and anything under system.data.

Any help would be much appreciated.

0
Comment
Question by:santuon
7 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 20276945
>>Is it possible to use ADO.Net to get the progress (ie % complete) of a sql query?<<
I very much doubt it, but see if using the STATS keyword helps.
0
 
LVL 3

Expert Comment

by:Aurora27
ID: 20277244
If the sql is called from an app, create a separate thread for it and spawn it with sql. Then, have a timer that tciks away and based on that show the progress using a progress bar.

You cal also get more stats based on how many records its updated. See the count of tables and the record, it has to back up and then based on whats been backed up, you can display the percentage.

CT.
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 20279460
SQL Server: Dataset Fill with ProgressBar

This is a kind of workaround for filling a dataset with a progressbar.

Used is the NorthWind SQL database as sample database, while the sample needs a datagrid and
a progressbar on a form.

Be aware that this sample uses a show in the load event. It is better not to do that. However in this case
to keep the sample simple, because otherwise a button was needed, which could confuse.

--------------------------------------------------------------------------------

Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
        Dim conn As New SqlClient.SqlConnection("Server=(local);" & _
                     "DataBase=Northwind; Integrated Security=SSPI")
        Dim cmd As New SqlClient.SqlCommand("Select Count(*) from Employees", conn)
        conn.Open()
        ProgressBar1.Maximum = DirectCast(cmd.ExecuteScalar, Integer)
        ProgressBar1.Step = 1
        ProgressBar1.Minimum = 0
        cmd.CommandText = "SELECT * FROM Employees"
        Dim rdr As SqlClient.SqlDataReader = cmd.ExecuteReader()
        Dim ds As New DataSet
        Dim dt As DataTable
        Show()
        'Normally is this "not done" in the load event,
        'you will see a strange datagrid
        While rdr.Read
            If dt Is Nothing Then
                dt = New DataTable
                Dim dtschema As DataTable
                dtschema = rdr.GetSchemaTable
                For Each drschema As DataRow In dtschema.Rows
                    dt.Columns.Add(drschema("ColumnName").ToString, _
                    Type.GetType(drschema("DataType").ToString))
                Next
            End If
            ProgressBar1.PerformStep()
            Dim dr As DataRow = dt.NewRow
            Dim tempObject(dt.Columns.Count - 1) As Object
            rdr.GetValues(tempObject) 'did not go in one time
            dr.ItemArray = tempObject
            dt.Rows.Add(dr)
            Threading.Thread.Sleep(500) 'only for showing
        End While
        ds.Tables.Add(dt)
        DataGrid1.DataSource = ds.Tables(0)
        rdr.Close()
        conn.Dispose()
End Sub
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:santuon
ID: 20316767
thanks for the help.

Solutions so far are work arounds. What I am actually looking for is weither ADO.Net has features build in to easily query the percentage complete of an SQL backup/restore. Without the need to guess or estimate table, files size etc.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 20317005
As I stated previously, unless you can use the STATS keyword you are SOL.  In other words "you cannot do that"
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20520519
Forced accept.

Computer101
EE Admin
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now