santuon
asked on
How to get progress of sql query using ADO.Net
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.
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.
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.
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.
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("S erver=(loc al);" & _
"DataBase=Northwind; Integrated Security=SSPI")
Dim cmd As New SqlClient.SqlCommand("Sele ct Count(*) from Employees", conn)
conn.Open()
ProgressBar1.Maximum = DirectCast(cmd.ExecuteScal ar, 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("C olumnName" ).ToString , _
Type.GetType(drschema("Dat aType").To String))
Next
End If
ProgressBar1.PerformStep()
Dim dr As DataRow = dt.NewRow
Dim tempObject(dt.Columns.Coun t - 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
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("S
"DataBase=Northwind; Integrated Security=SSPI")
Dim cmd As New SqlClient.SqlCommand("Sele
conn.Open()
ProgressBar1.Maximum = DirectCast(cmd.ExecuteScal
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("C
Type.GetType(drschema("Dat
Next
End If
ProgressBar1.PerformStep()
Dim dr As DataRow = dt.NewRow
Dim tempObject(dt.Columns.Coun
rdr.GetValues(tempObject) 'did not go in one time
dr.ItemArray = tempObject
dt.Rows.Add(dr)
Threading.Thread.Sleep(500
End While
ds.Tables.Add(dt)
DataGrid1.DataSource = ds.Tables(0)
rdr.Close()
conn.Dispose()
End Sub
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
I very much doubt it, but see if using the STATS keyword helps.