本文介绍了全球职能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试设置一个连接数据库的函数,我可以使用然后使用gloablly。我建立了一个名为L3Global的课程,其中我有一个 函数,如下所示: 公共函数SetDBConnect() Dim ConnStrL3Producer As String ConnStrL3Producer =" User ID = UID; possible = False; Data Source =" &安培; Chr(34)& " A.B.C.D" &安培; Chr(34)& " ;;密码= PWD;" ConnStrL3Producer = ConnStrL3Producer& 初始目录= L3;使用程序 for Prepare = 1; Auto Translate = True; Persist Security Info = True; Provider =" ConnStrL3Producer = ConnStrL3Producer& Chr(34)& " SQLOLEDB.1" &安培; Chr(34)& " ;; Workstation ID = AUM; Use Encryption for Data = False; Packet Size = 4096" Dim ConnL3Producer As New OleDbConnection(ConnStrL3Producer) 返回ConnL3Producer 结束功能 现在我想使用这是我的所有形式(MDI)。我设置了 公共L3G作为新的L3Global 然后根据approporate按钮点击我有: Dim ConnL3Producer As New OleDbConnection ConnL3Producer = L3G.SetDBConnect 问题是,我是否必须在每种形式中设置L3Global的实例? 这会破坏目的,因为每个人都会打开一个新连接。怎么能 我在所有表格中都使用这个连接对象,但只打开一次?理想情况下 我想尽可能多地移动初始化(创建OLEDBAdapter 等)到全局例程。 Thanx任何建议。 - Anil Gupte www.keeninc.net www.icinema.com 解决方案 I am trying to set up a function that connects to the database that I canthen use gloablly. I set up a class called L3Global in which I have afunction as follows: Public Function SetDBConnect()Dim ConnStrL3Producer As StringConnStrL3Producer = "User ID=UID;Tag with column collation whenpossible=False;Data Source=" & Chr(34) & "a.b.c.d" & Chr(34) &";Password=PWD;"ConnStrL3Producer = ConnStrL3Producer & "Initial Catalog=L3;Use Procedurefor Prepare=1;Auto Translate=True;Persist Security Info=True;Provider="ConnStrL3Producer = ConnStrL3Producer & Chr(34) & "SQLOLEDB.1" & Chr(34) &";Workstation ID=AUM;Use Encryption for Data=False;Packet Size=4096"Dim ConnL3Producer As New OleDbConnection(ConnStrL3Producer)Return ConnL3ProducerEnd Function Now I want to use this is all my forms (MDI). I set upPublic L3G As New L3Global and then under the approporate button click I have:Dim ConnL3Producer As New OleDbConnection ConnL3Producer = L3G.SetDBConnect The problem is, do I have to setup an instance of L3Global in each form?That defeats the purpose, because each one opens a new connection. How canI use this connection object in all my forms but open it only once? IdeallyI would like to move as much of the intialization (creating the OLEDBAdapteretc) to the global routine. Thanx for any suggestions.--Anil Gupte www.keeninc.net www.icinema.com 解决方案 这篇关于全球职能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-19 01:07