Hello!! I'm development a web application in n-tiers. The UI have a web.config, and the other tiers using app.config. The problem is that the application doesn´t recognize the app.config files. Only the web.config of the UI. For example: I try to put the connections string in a app.config in the data access, but when it runing, throws a error that says: "Database undefined". But when I put the connections strings in the web.config, it runing well. I need help!!!
To use xml atributes from WebConfig and AppConfig u must add referance to System.Configuration nemspase and
then u can call your atributes like this
1 string s = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString;// example u have xml atribute in webconfig or in appconfig name "conn" this will call your coonnection string when u call from winapp from AppConfig// and when u call from web this will return the connection string from webconfigI use like this and it works perfektly.Sorry for my bad english
thanks!!!! But it doesn't solve my problem I tried with the ConfigurationManager function, but it doesn't working. The data access layer (DAL), for example, do reference to the configuration file (web.config) of the UI. If I add the connections string in the app.config of the DAL. It throws the error message: database undefined, it's to say the it didn't the connection string.
I dont know why it is not workin hear is another example
in DB layer i hawe 2 files one is DB.cs and BankMapper.cs in DB i hawe followin method
public static string getConnection()
string s System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
on the BankMapper i hawe followin method
public List<Bank> Load()
List<Bank> us = new List<Bank>();
SqlConnection con = new SqlConnection(DB.getConnection());
SqlCommand cmd = new SqlCommand("Proc", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader rdr = cmd.ExecuteReader();
us.ID = (int) rdr["ID"];
us.First = (string) rdr["Name"];
throw(new DBLayerException(ex.Message, ex.Number, ex));
in your WebConfig and in your AppConfig u must hawe the connection string like this example
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=AvukFitDB;Integrated Security=True;Pooling=False"
if u did this it must work only if u hawe another problem. if u hawe still problem please post exeption message herar.
Sorry for my bad english
The problem isn't read a app.config or web.config, it's do that the application recogonize the correct configuration file. Your code is so good, but try to add a app.config in the data access layer and also add a web.config in the UI. According to other forum, the problem is that the webApplication reference to the configuration file, not the asembly's. R/ http://forums.asp.net/p/1166886/1943282.aspx#1943282 But, I like find other solution, because I'm using application blocks and I don't know have all the information in a configuration file in the UI. Thanks a lot!!!!
alvarohv:Hello!! I'm development a web application in n-tiers. The UI have a web.config, and the other tiers using app.config. The problem is that the application doesn´t recognize the app.config files. Only the web.config of the UI. For example: I try to put the connections string in a app.config in the data access, but when it runing, throws a error that says: "Database undefined". But when I put the connections strings in the web.config, it runing well. I need help!!!
I also develop n-tire applications and they read information about connection string at Data Access Layer. I managed to read web.config (which is at the UI) from DAL and everything works fine. Do not know if this is your problem...
app.config and System.Configuration.ConfigurationManager also does not work at my applications...
This is my web.config:
<configuration> <appSettings> <add key="conn_string" value="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=sdl_edu;Data Source=BB-979E858132F7" /> </appSettings>
And I have this C# code:
protected string my_connstring = ConfigurationSettings.AppSettings["conn_string"];
I see the manage of the configurations from a configuration file in the UI, can bring security problems. Because, the Data access should independently of the other layers. Also, in my case, the application have the posibility that work in an server the UI and in other server the Data Access, joined by a complex Bussiness Layer. Finally a opcional thing that I found in the web is: http://codebetter.com/blogs/david.hayden/archive/2006/01/08/136360.aspx However, I thing that it doesn't working the Logging Application Block
Seems this thread is duplicate with your another one in VS 2005 Web Application Projects forum. Please open the following link and check it. Thanks.
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
Why would you want to do this anyways? I understand the separation of the different layers but the web.config file is not just for UI layers. The root level web.config file specifies properties for the entire web application. As far as security goes it really isn't a big deal since the server will never serve up the file.
Or did I miss the point?