c#中VB.NET模块的替代方案? [英] alternative for VB.NET module in c#?

查看:132
本文介绍了c#中VB.NET模块的替代方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我的vb应用程序中的
,我过去常常使用一个存储全局变量的模块,但是在c#中这不是
这似乎没有存在,我想做的是创建全局

sqlcommand,sqlconnection变量,可以在应用程序内的任何地方重复使用。


请指教。

谢谢,

Paul

hi there,

in my vb apps, i used to use a module where i stored global variables, but
in c# this doesnt seem to exist, what i want to do is create global
sqlcommand,sqlconnection variables that can be reused from anywhere within
the app.

please advise.
thanks,
Paul

推荐答案

这听起来像静态属性,例如


公共静态类GlobalData {

公共静态字符串PrimaryConnectionString {get; set;} //详细信息

未显示

}


3个额外的想法:

*您可能会受益于使用内置池而不是保持

显式SqlConnection打开 - 特别是随着复杂性的增加

(因此我用连接STRING表示不是连接)

*正常的线程安全规则适用于静态成员

*当然,更好的opti on(对于连接字符串)可能是

使用ConfigurationManager类和配置文件


Marc
This sounds like static properties, e.g.

public static class GlobalData {
public static string PrimaryConnectionString {get;set;} // details
not shown
}

3 additional thoughts:
* You might benefit from using the inbuilt pooling rather than keeping
an explicit SqlConnection open - particularly as complexity increases
(hence I illustrated with a connection STRING not a connection)
* Normal thread-safety rules apply to static members
* Of course, a better option (for connection strings) would might be
to use the ConfigurationManager classes and a config file

Marc

" Marc Gravell" < ma ********** @ gmail.comwrote in message

news:e3 **************** @ TK2MSFTNGP04.phx .gbl ...
"Marc Gravell" <ma**********@gmail.comwrote in message
news:e3****************@TK2MSFTNGP04.phx.gbl...

*您可能会受益于使用内置池而不是保持一个明确的SqlConnection打开 - 特别是随着复杂性的增加(因此

我说明了连接STRING而不是连接)
* You might benefit from using the inbuilt pooling rather than keeping an
explicit SqlConnection open - particularly as complexity increases (hence
I illustrated with a connection STRING not a connection)



绝对。应用程序应该做的最后一件事是保持一个永久的

打开数据库链接。对于网络应用来说尤其如此......

Absolutely. The last thing an application should do is keep a permanently
open link to a database. This is especially true of web apps...


*当然,更好的选择(对于连接字符串)可能是

使用ConfigurationManager类和配置文件
* Of course, a better option (for connection strings) would might be to
use the ConfigurationManager classes and a config file



绝对。

Definitely.


感谢所有回复。


我的问题是基于一个Windows.NET c#桌面应用程序,而不是一个web

应用程序,所以我认为最好保持连接打开,直到

用户是否退出应用程序?


至于连接字符串,我正在使用App.Config将字符串存储在
$ b $中b在那里并在运行期间将其读入应用程序。


问候,

Paul

" Mark Rae" < ma ** @ markNOSPAMrae.netwrote in message

news:%2 **************** @ TK2MSFTNGP04.phx.gbl ...
Thanks for all replies.

My question was based for a Windows.NET c# desktop application, not a web
application so i assume its better to keep the connection open until the
user logs out of the application, or not?

As for the connectionstring, i''m using App.Config to store the string in
there and read it into the app during run-time.

regards,
Paul
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...

" Marc Gravell" < ma ********** @ gmail.comwrote in message

news:e3 **************** @ TK2MSFTNGP04.phx .gbl ...
"Marc Gravell" <ma**********@gmail.comwrote in message
news:e3****************@TK2MSFTNGP04.phx.gbl...

> *您可能会受益于使用内置池而不是保持显式SqlConnection开放 - 特别是随着复杂性的增加(因此
我说明连接STRING不是连接)
>* You might benefit from using the inbuilt pooling rather than keeping an
explicit SqlConnection open - particularly as complexity increases (hence
I illustrated with a connection STRING not a connection)



绝对。应用程序应该做的最后一件事是保持一个永久的

打开数据库链接。对于网络应用来说尤其如此......


Absolutely. The last thing an application should do is keep a permanently
open link to a database. This is especially true of web apps...


> *当然,更好的选择(对于连接字符串)可能是
使用ConfigurationManager类和配置文件
>* Of course, a better option (for connection strings) would might be to
use the ConfigurationManager classes and a config file



绝对。


Definitely.



这篇关于c#中VB.NET模块的替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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