在 Visual Studio 2012 VB 项目中更改表适配器(调用存储过程)的超时时间? [英] Change timeout for table adapter (call stored procedure) in Visual Studio 2012 VB project?

查看:24
本文介绍了在 Visual Studio 2012 VB 项目中更改表适配器(调用存储过程)的超时时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:调用存储过程在 30 秒后超时.似乎自动生成的表适配器没有提供更改它的接口.

My problem: Call to a Stored Procedure is timing out after 30 seconds. Seems the auto-generated table adapter doesn't provide an interface to change it.

问题:如何更改 SP 调用的超时值?

Question: How can I change the timeout value for my SP call?

环境:Visual Studio 2012,VB.NET 中的代码,数据库:SQL Server 2008 R2.我将数据集与数据集设计器一起用于 CRUD 操作并调用存储过程.自动生成的表适配器从代码中调用.

Environment: Visual Studio 2012, Code in VB.NET, database: SQL Server 2008 R2. I am using a dataset with the DataSet Designer for CRUD operations and also calling Store Procedures. The auto-generated table adapters are called from code.

研究已经完成:我已经为 C# 项目找到了一些答案,但我在语言方面的经验很少:发布 1

Research already done: I have found some answers for C# projects, but I have little experience in the language: post 1

推荐答案

由于您使用的是强类型 TableAdapter,它仅将 DataAdapter 保持为 protected 属性,您不能更改所有 SqlCommandCommandTimeouts 直接.你可以做的是扩展这个自动生成的类(它是一个 Partial Class).因此在同一目录中创建另一个同名的类,例如:Public Partial Class YourTableAdapter.

Since you're using a strongly typed TableAdapter which just holds the DataAdapter as protected property, you cannot change all SqlCommand's CommandTimeouts directly. What you can do is to extend this autogenerated class(it's a Partial Class). Therefore create another class with the same name in the same directory, for example: Public Partial Class YourTableAdapter.

现在您可以创建可以访问 DataDapter 的新属性或方法.请注意,该类必须位于相同的(自动生成的)命名空间中.例如:

Now you're able to create new properties or methods which can access the DataDapter. Note that the class has to sit in the same (autogenerated) namespace. For example:

Namespace ApplicationName.DataSetNameTableAdapters
    Partial Public Class YourTableAdapter
        Public Property CommandTimeout As Int32
            Get
                Return Me.CommandCollection(0).CommandTimeout
            End Get
            Set(value As Int32)
                For Each cmd As SqlCommand In Me.CommandCollection
                    cmd.CommandTimeout = value
                Next
            End Set
        End Property
    End Class
End NameSpace

不要扩展原始类(.designer.vb),它会在设计器中的每次更改时被覆盖.

Don't extend the original class (.designer.vb), it will be overwritten on every change in the designer.

现在您可以:

Dim adapter = new YourTableAdapter()
adapter.CommandTimeout = 60 * 30  ' 30 minutes 

这篇关于在 Visual Studio 2012 VB 项目中更改表适配器(调用存储过程)的超时时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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