全球职能 [英] Global Functions
问题描述
我正在尝试设置一个连接数据库的函数,我可以使用
然后使用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
我不会在.Net中建议全球连接方式
由于卓越的连接池机制,你现在可以安全地和没有任何性能开销的b $ b创建,使用和销毁
特别是using语句是非常方便用这个
亲自将连接字符串存储在配置文件中
问候
Michel
" Anil Gupte" < a ******* @ icinema.comschreef在bericht
新闻:************** @ TK2MSFTNGP06.phx.gbl ...
>我正在尝试设置一个连接数据库的函数,然后我可以使用它。我建立了一个名为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
Thanx的提示,但请解释:
" ...特别是使用声明非常方便这个
和还有
" ...我个人将连接字符串存储在配置文件中
我是.Net的新手,上次使用的是VB 5几年前。几个月。
-
Anil Gupte
www.keeninc。网
www.icinema.com
Michel Posseth [MCP]" < MS ** @ posseth.comwrote in message
news:eq ************** @ TK2MSFTNGP04.phx.gbl ...
< blockquote class =post_quotes>
>
我不会在.Net中建议一个全局连接方法
因为一流的连接池机制,你现在可以安全地和没有任何性能开销创建,使用和销毁
特别是使用语句非常方便这个
我亲自将连接字符串存储在配置文件中
问候
米歇尔
" Anil Gupte" < a ******* @ icinema.comschreef在bericht
新闻:************** @ TK2MSFTNGP06.phx.gbl ...
>>我正在尝试设置一个连接数据库的函数,然后我可以使用它。我建立了一个名为L3Global的类,其中我的功能如下:
Public Function SetDBConnect()
Dim ConnStrL3Producer As String
ConnStrL3Producer =" User ID = UID;当
可能= False时标记列整理;数据源=" &安培; Chr(34)& " A.B.C.D" &安培; Chr(34)&
" ;; Password = PWD;"
ConnStrL3Producer = ConnStrL3Producer& 初始目录= L3;使用程序
准备= 1;自动翻译=真;持久安全信息=真;提供者="
ConnStrL3Producer = ConnStrL3Producer& Chr(34)& " SQLOLEDB.1" &安培; Chr(34)
& " ;;工作站ID = AUM;使用数据加密= False;数据包大小= 4096
Dim ConnL3Producer作为新OleDbConnection(ConnStrL3Producer)
返回ConnL3Producer
结束功能
然后在approporate按钮下点击我有:
Dim ConnL3Producer作为新的OleDbConnection
ConnL3Producer = L3G .SetDBConnect
问题是,我是否必须在每种形式中设置L3Global实例?
这会破坏目的,因为每个人都会打开一个新连接。我可以在所有表单中使用这个连接对象,但只打开一次吗?
理想情况下,我希望尽可能多地将初始化(创建
OLEDBAdapter等)移动到全局例程中。
Thanx任何建议。
-
Anil Gupte
www.keeninc.net
www.icinema.com
我不知道你有没有你还没有听说过我认为的设计模式
你应该花点时间阅读它们。以下是概述:
http://en.wikipedia.org /wiki/Design_...mputer_science )
特别是你在描述一个Singleton模式(这里有代码在
C#中,你可以看看)
http://en.wikipedia.org/wiki / Singleton_pattern
" Anil Gupte" < an ******* @ icinema.comwrote in message
news:************** @ TK2MSFTNGP06.phx.gbl ...
>我正在尝试设置一个连接数据库的函数,然后我可以使用它。我建立了一个名为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 can
then use gloablly. I set up a class called L3Global in which I have a
function as follows:
Public Function SetDBConnect()
Dim ConnStrL3Producer As String
ConnStrL3Producer = "User ID=UID;Tag with column collation when
possible=False;Data Source=" & Chr(34) & "a.b.c.d" & Chr(34) &
";Password=PWD;"
ConnStrL3Producer = ConnStrL3Producer & "Initial Catalog=L3;Use Procedure
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)
Return ConnL3Producer
End Function
Now I want to use this is all my forms (MDI). I set up
Public 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 can
I use this connection object in all my forms but open it only once? Ideally
I would like to move as much of the intialization (creating the OLEDBAdapter
etc) to the global routine.
Thanx for any suggestions.
--
Anil Gupte
www.keeninc.net
www.icinema.com
Well i would not recomend a global connection aproach in .Net
Because of the superb connection pool mechanism , you can now safely and
without anny performance overhead create , use , and destroy
especially the using statement is verry handy with this
personally i would store the connection string in the config file
regards
Michel
"Anil Gupte" <an*******@icinema.comschreef in bericht
news:Of**************@TK2MSFTNGP06.phx.gbl...>I am trying to set up a function that connects to the database that I can
then use gloablly. I set up a class called L3Global in which I have a
function as follows:
Public Function SetDBConnect()
Dim ConnStrL3Producer As String
ConnStrL3Producer = "User ID=UID;Tag with column collation when
possible=False;Data Source=" & Chr(34) & "a.b.c.d" & Chr(34) &
";Password=PWD;"
ConnStrL3Producer = ConnStrL3Producer & "Initial Catalog=L3;Use Procedure
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)
Return ConnL3Producer
End Function
Now I want to use this is all my forms (MDI). I set up
Public 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
can I use this connection object in all my forms but open it only once?
Ideally I would like to move as much of the intialization (creating the
OLEDBAdapter etc) to the global routine.
Thanx for any suggestions.
--
Anil Gupte
www.keeninc.net
www.icinema.com
Thanx for that tip, but please explain:
"...especially the using statement is verry handy with this"
and also
"...personally i would store the connection string in the config file"
I am a newbie at .Net and last used VB five years ago for a few months.
--
Anil Gupte
www.keeninc.net
www.icinema.com
"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:eq**************@TK2MSFTNGP04.phx.gbl...>
Well i would not recomend a global connection aproach in .Net
Because of the superb connection pool mechanism , you can now safely and
without anny performance overhead create , use , and destroy
especially the using statement is verry handy with this
personally i would store the connection string in the config file
regards
Michel
"Anil Gupte" <an*******@icinema.comschreef in bericht
news:Of**************@TK2MSFTNGP06.phx.gbl...>>I am trying to set up a function that connects to the database that I can
then use gloablly. I set up a class called L3Global in which I have a
function as follows:
Public Function SetDBConnect()
Dim ConnStrL3Producer As String
ConnStrL3Producer = "User ID=UID;Tag with column collation when
possible=False;Data Source=" & Chr(34) & "a.b.c.d" & Chr(34) &
";Password=PWD;"
ConnStrL3Producer = ConnStrL3Producer & "Initial Catalog=L3;Use Procedure
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)
Return ConnL3Producer
End Function
Now I want to use this is all my forms (MDI). I set up
Public 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
can I use this connection object in all my forms but open it only once?
Ideally I would like to move as much of the intialization (creating the
OLEDBAdapter etc) to the global routine.
Thanx for any suggestions.
--
Anil Gupte
www.keeninc.net
www.icinema.com
I can''t know if you have but if you haven''t heard of design patterns I think
you should spend a little time reading about them. Here is an overview:
http://en.wikipedia.org/wiki/Design_...mputer_science)
Particularly you are describing a Singleton pattern (there is code here in
C# which you can take a look at)
http://en.wikipedia.org/wiki/Singleton_pattern
"Anil Gupte" <an*******@icinema.comwrote in message
news:Of**************@TK2MSFTNGP06.phx.gbl...>I am trying to set up a function that connects to the database that I can
then use gloablly. I set up a class called L3Global in which I have a
function as follows:
Public Function SetDBConnect()
Dim ConnStrL3Producer As String
ConnStrL3Producer = "User ID=UID;Tag with column collation when
possible=False;Data Source=" & Chr(34) & "a.b.c.d" & Chr(34) &
";Password=PWD;"
ConnStrL3Producer = ConnStrL3Producer & "Initial Catalog=L3;Use Procedure
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)
Return ConnL3Producer
End Function
Now I want to use this is all my forms (MDI). I set up
Public 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
can I use this connection object in all my forms but open it only once?
Ideally I would like to move as much of the intialization (creating the
OLEDBAdapter etc) to the global routine.
Thanx for any suggestions.
--
Anil Gupte
www.keeninc.net
www.icinema.com
这篇关于全球职能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!