如何设计器生成的表适配器处理连接 [英] How do designer-generated table adapters handle connections
问题描述
如何表适配器使用的连接?
How do table adapters make use of connections?
要解释一下,他们是否会自动打开和关闭连接,或者如果我已经有了连接调用一个TableAdapter方法之前开放的,他们使用它,并把它打开?
To explain that a bit, do they automatically open and shut connections or if I already have the connection open before calling a tableadapter method, do they use it and leave it open?
问候
推荐答案
如果你看一下设计器生成的code,你会看到,如果有一个连接,适配器将重新使用它,否则它创建一个新的一个。当执行一个查询方法,如果连接没有打开,该方法将其打开。如果该方法打开了它,它会关闭它,当它完成。默认情况下你为每个表适配器一个新的连接。
If you look at the designer-generated code, you'll see that if there is a connection, the adapter reuses it, otherwise it creates a new one. When executing a query method, if the connection isn't open, the method opens it. If the method opened it, it closes it when it is done. By default you get a new connection for every table adapter.
这篇关于如何设计器生成的表适配器处理连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!