如何更改大量TableAdapter的CommandTimeout [英] How to change CommandTimeout for a large number of TableAdapters

查看:140
本文介绍了如何更改大量TableAdapter的CommandTimeout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用强类型数据集开发的复杂数据库应用程序,虽然它们提供了一种非常简单且可靠的访问数据库的方法,但有一个缺点是CommandTimeout属性是"硬连线"的。到30秒。
看来改变这种情况的唯一方法是为tableadapter创建一个局部类,例如



命名空间DALCompaniesTableAdapters 
部分公开类CompaniesTableAdapter
Public WriteOnly属性CommandTimeout()As Integer
Set(ByVal value As Integer)
Dim Command As System.Data.SqlClient.SqlCommand
For CommandCollection $ b中的每个命令$ b If(Command IsNot Nothing)然后
Command.CommandTimeout = value
结束如果
下一个
结束集
结束物业
结束等级


这被引用:

使用CustAdap作为新的DALCompaniesTableAdapters.Custo merTableAdapter 
CustAdap.CommandTimeout = DbTimeout
CustAdap.CustomerDelete(Me.Id,RetVal)
...................... ...

结束使用

虽然此解决方案适用于少量适配器,但它需要为特定代码编写代码每个适配器都有一个更改的调用。


因为我的应用程序可能与许多数据库一起工作(即不同的连接字符串)我创建了自己的类:

命名空间My 

Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration .ApplicationSettingsBase

     Private Sub userOverride_SettingsLoaded(ByVal sender As Object,ByVal e As System.Configuration.SettingsLoadedEventArgs)_
           处理Me.SettingsLoaded

函数userOverride设置所有表适配器使用的正确命令字符串 - 这非常有用。


我的问题是:是否有类似的方法可以使用CommandTimout实现相同的功能?


帮助赞赏


PaulI


 



Paul Ireland

解决方案

您可以使用部分类扩展TableAdapter的功能,这是您可以使用的地方实现CommandTimeout功能。以下链接包含您可以如何做的示例


http:// www。 codeproject.com/KB/database/TableAdaptrCommandTimeout.aspx


I have a complex database application that has been developed using strongly type datasets, while these provide a very easy and robust way of accessing a database, there is one shorcoming in that the CommandTimeout property is "hard wired" to 30 seconds. It would appear the only way to change this is to create a partial class for the tableadapter, e.g.

Namespace DALCompaniesTableAdapters
 Partial Public Class CompaniesTableAdapter 
   Public WriteOnly Property CommandTimeout() As Integer 
    Set(ByVal value As Integer) 
     Dim Command As System.Data.SqlClient.SqlCommand 
      For Each Command In CommandCollection 
       If (Command IsNot Nothing) Then
        Command.CommandTimeout = value   
       End If 
      Next 
   End Set 
  End Property 
 End Class 

This is referenced by:

   Using CustAdap As New DALCompaniesTableAdapters.CustomerTableAdapter
   CustAdap.CommandTimeout = DbTimeout
   CustAdap.CustomerDelete(Me.Id, RetVal)
   .........................

   End Using
 

While this solution works well for small number of adapters, it requires specific code to be written for each adapter with a change to the call.

Because my application may work with a number of databases (i.e. different connection string) I have created my own class:

Namespace My

 Partial Friend NotInheritable Class MySettings
 Inherits Global.System.Configuration.ApplicationSettingsBase

     Private Sub userOverride_SettingsLoaded(ByVal sender As Object, ByVal e As System.Configuration.SettingsLoadedEventArgs) _
            Handles Me.SettingsLoaded

The function userOverride set the correct command string that is used by ALL table adapters - this works very well.

My question is: Is there a similar way to achive the same functionalty with CommandTimout?

Help appreciated

PaulI

 

Paul Ireland

解决方案

You can extend functionality of TableAdapter using partial classes and this is where you can implement CommandTimeout functionality. Following link contains sample how you could do it

http://www.codeproject.com/KB/database/TableAdaptrCommandTimeout.aspx


这篇关于如何更改大量TableAdapter的CommandTimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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