执行长时间的存储过程时,显示进度条的百分比. [英] Show percentage of progress bar while execute long process of store procedure.

查看:170
本文介绍了执行长时间的存储过程时,显示进度条的百分比.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我想显示在sql server 2005上执行存储过程时的处理百分比:

''''''App.config文件

Dear All,

I want to show % of processing while execute store procedure on sql server 2005:

''''''App.config file

<appSettings>
    <add key="CON" value="Data Source=SERVER;Initial Catalog=Reporting;Persist Security Info=True;User ID=user; password =123"/>
    <add key="AsynCON" value="Data Source=SERVER\MBWIN;Initial Catalog=Reporting;Persist Security Info=True;Asynchronous Processing=true;User ID=user; password =123"/>
  </appSettings>



''''--------------------------------------



''''--------------------------------------

Private Sub CmdTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdTest.Click
        Dim myWatch = New Stopwatch() '' use stopWath class to keep track of performent.
        myWatch.Start()
        timeCount = 0
        Dim strAsyn = ConfigurationManager.AppSettings("AsynCON")
        SQLAsynConnect = New SqlConnection(strAsyn)

        dtData = New DataTable
        'dataAdabter = New SqlDataAdapter
        command = New SqlCommand
        command.CommandType = CommandType.StoredProcedure
        command.Connection = SQLAsynConnect
        command.CommandText = "Ysp_LoanProvisionWeekly"
        command.CommandTimeout = 3000
        command.Parameters.Add("@BRANCHCODE", SqlDbType.NVarChar).Value = "KCM"
        SQLAsynConnect.Open()

        Dim myResult As IAsyncResult = command.BeginExecuteReader()
        While Not myResult.IsCompleted
            timeCount = timeCount + Double.Parse(Convert.ToDecimal(myWatch.Elapsed.TotalSeconds.ToString()))
            pgrPer3.Value = timeCount '' progress bar pgrPer3
            If timeCount = 100 Or timeCount > 100 Then
                timeCount = 0
            End If
        End While
        myReader = command.EndExecuteReader(myResult)
        myWatch.Stop()
        dtData = New DataTable()
        dtData.Load(myReader)
        pgrPer3.Value = 100
        dgData.DataSource = dtData
    End Sub  


''''--------------------------------

问题在于,进度条在
期间未显示正确的百分比值 执行存储过程.
请帮帮我..


''''--------------------------------

The problem is that, the progress bar not show the right values of percentage during
execute store procedure.
Please help me..
thank.

推荐答案

尝试一下:
Try this:
pgrPer3.Value = timeCount ' progress bar pgrPer3
Application.DoEvents()


尝试一下:
Try this one :
ProgressBar1.Value = CInt((timeCount / 3000) * 100)


如果没有出现错误,请尝试从您的代码中忽略此部分:


And try to ignore this section from your code if error not come :

If timeCount = 100 Or timeCount > 100 Then
        timeCount = 0
End If


这取决于您如何实现存储过程.如果它是一个大的SQL语句,它将在一个批处理中运行,因此您将无法从服务器引发任何事件.

但是,如果将过程分解为许多SQL语句,则可以使用InfoMessage方法在整个存储过程执行期间引发事件.

http://geekswithblogs.net/mrnat/archive/2004/09/20/11431.aspx [^ ]

这样,将在执行过程的不同部分时通知您的应用程序.您可以相应地更新进度栏.
It depends how you''ve implemented your stored procedure. If it''s one big SQL Statement, it''s going to run in a single batch so you''ve got no way to raise any events from the server.

However, if your procedure is broken down into numerous SQL statements you could use the InfoMessage approach to raise events throughout your stored procedure execution

http://geekswithblogs.net/mrnat/archive/2004/09/20/11431.aspx[^]

This way, your application is notified as different parts of the procedure are executed & you can update your progress bar accordingly.


这篇关于执行长时间的存储过程时,显示进度条的百分比.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆