我是新来的桌面应用程序的开发和目前正在建设使用分层架构(用户界面,DAL,BLL)的桌面应用程序。
I am new to desktop application development and currently building a desktop application using layered architecture (user interface, DAL, BLL).
在web开发我用来存放在web.config中的连接字符串和我的类库是从那里访问它。请指导我如何和放大器;其中,连接字符串应存放于DAL在桌面应用程序。我想在我的课库中添加的app.config
文件和访问这样的连接字符串:
In web development I used to store the connection string in web.config and my class library was accessing it from there. Please guide me how & where connection string should be stored for DAL in desktop application. I tried to add an app.config
file in my class library and access the connection string like this:
ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString)
但throuws错误:。未将对象引用设置到对象的实例的
请指导我在此。感谢您的支持和分享。
Kindly guide me on this. Thanks for your support and sharing.
是的,在一个桌面应用程序,所有的配置应该在的app.config
该应用程序。使用该桌面应用程序将得到他们的配置从的app.config
默认的类库。
Yes, in a desktop application, all configuration should be in the app.config
for that application. The class libraries used by this desktop application will get their config from that app.config
by default.
如果该行抛出一个异常:
If this line throws an exception:
ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString
那么它极有可能是因为没有<的ConnectionStrings>
的名称输入ConnectionString的存在。检查空:
then it's most likely because no <connectionStrings>
entry of name "connectionstring" exists. Check for NULL:
if(ConfigurationManager.ConnectionStrings["connectionstring"] != null)
{
string connStr = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
}
上一篇:自动HTML编码NVelocity输出(EventCartridge&安培; ReferenceInsert)安培、NVelocity、HTML、ReferenceInsert
下一篇:java.lang.NumberFormatException:无效INT:&QUOT;&QUOT;lang、java、NumberFormatException、QUOT