[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to get progress of  sql query using ADO.Net

Posted on 2007-11-13
7
Medium Priority
?
2,198 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

650 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