?
Solved

How to get progress of  sql query using ADO.Net

Posted on 2007-11-13
7
Medium Priority
?
2,193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 

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 2000 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Suggested Courses

770 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