This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / a question for asp.net configurationI have a solution with asp.net project as main project and some other projects, like this:
- main project (asp.net project)
default.aspx
web.config
- project1 (data access layer project)
project.cs
I try to save database connection string in configuration file, then use it in data access layer project, how can I do that?
(I can not use web.config file, because it is only for the web project. and I tried to create App.config in the second project, don't know why it didn't work.)
thanks.
-hillxie(我叫不紧张);
2004-1-7
{509}
(#1550274@0)
-
at least, you can have another xml file storing those settings.
-win(秋天的菠菜);
2004-1-7
(#1550278@0)
-
I try to find an easy way without my own configuration file, and look for a way to only use ConfigurationSettings.AppSettings["SqlConnectionString"] to retrieve the connection string. not sure if it is possible.
-hillxie(我叫不紧张);
2004-1-7
(#1550295@0)
-
did you try HttpContext class?
-win(秋天的菠菜);
2004-1-7
(#1550281@0)
-
no. is this class helpful for my case?
-hillxie(我叫不紧张);
2004-1-7
(#1550285@0)
-
this class has some members like "Application" or "GetAppConfig", which might be useful to you.
-win(秋天的菠菜);
2004-1-7
(#1550297@0)
-
I have to make my question more clear: in case I want to test the data access layer project within another poject(not web project), how and where can I save the database connection string?
-hillxie(我叫不紧张);
2004-1-7
(#1550355@0)
-
No way. If you use source safe, you can keep a local file to read configurations.public static string getConnectionString()
{
if (ConfigurationSettings.AppSettings["ConnectionString"]==null)
{
return ( "whatever connection string you hard code here for your none web applications");
}
else
{
return ( ConfigurationSettings.AppSettings["ConnectionString"] );
}
}
-wnms2000(乘风归去);
2004-1-7
{312}
(#1550400@0)
-
谢谢楼上二位,看来没有更直接了当的方法了。
-hillxie(我叫不紧张);
2004-1-8
(#1551235@0)