App.config/web.config

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!!!
Alvaro Hdez
Developer
0
alvarohv
10/5/2007 5:20:23 PM
asp.net.ajax-ui 9760 articles. 0 followers. Follow

8 Replies
1404 Views

Similar Articles

[PageSpeed] 19

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 webconfig
 
I use like this and it works perfektly.
 
Sorry for my bad english
 
 
 
Florim Maxhuni
0
florim
10/5/2007 6:36:48 PM
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.
Alvaro Hdez
Developer
0
alvarohv
10/5/2007 9:57:43 PM

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;
            return s;
        }

on the BankMapper i hawe followin method

public List<Bank> Load()
  {
   
   List<Bank> us = new List<Bank>();
 
   SqlConnection con = new SqlConnection(DB.getConnection());
   try
   {
    con.Open();

    SqlCommand cmd = new SqlCommand("Proc", con);
    cmd.CommandType = CommandType.StoredProcedure;

    HelpClass.addParamIn(cmd,"@UserID",SqlDbType.SmallInt, us.ID);

    SqlDataReader  rdr = cmd.ExecuteReader();

    if(rdr.Read())
    {
     us.ID = (int) rdr["ID"];
     us.First  = (string) rdr["Name"];
     
    }
    
    rdr.Close();
    cmd.Dispose();
    con.Close();
   }
   catch(SqlException ex)
   {
    throw(new DBLayerException(ex.Message, ex.Number, ex));
   }
   finally
   {
    con.Close();
    con.Dispose();
   }  
  }

 in your WebConfig and in your AppConfig u must hawe the connection string like this example

<connectionStrings>
    <add name="conn"
        connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=AvukFitDB;Integrated Security=True;Pooling=False"
        providerName="System.Data.SqlClient" /></connectionStrings>

 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


Florim Maxhuni
0
florim
10/6/2007 11:34:42 AM
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!!!!
Alvaro Hdez
Developer
0
alvarohv
10/6/2007 4:38:58 PM

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"]; 



 

0
marko
10/6/2007 5:39:16 PM
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
Alvaro Hdez
Developer
0
alvarohv
10/6/2007 7:08:36 PM

Hi alvarohv,

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.

App.config/Web.cong
http://forums.asp.net/p/1166886/1943756.aspx

 


Sincerely,
Benson Yu
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.
0
Benson
10/11/2007 6:26:39 AM

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?

 Brent


Brent

http://www.brentpabst.com
http://www.pabstproductions.com
0
rikishipabst
10/11/2007 7:00:27 AM
Reply:

Web resources about - App.config/web.config - asp.net.ajax-ui

Proxy auto-config - Wikipedia, the free encyclopedia
Computer operating systems (e.g., Microsoft Windows , Mac OS X , Linux ) require a number of settings to communicate over the Internet . These ...

Platform Updates: New Industry Pages, Refreshed Services Status Page, and New Parse Config Dashboard
Platform Updates: New Industry Pages, Refreshed Services Status Page, and New Parse Config Dashboard

App Config for Android - YouTube
Free version: https://play.google.com/store/apps/details?id=fi.aarosoft.appconfig.free Full version: https://play.google.com/store/apps/deta ...

HP unveils cloud config manager
HP this week unveiled a network virtualization system for large enterprise and cloud providers designed to simplify network configuration.

China configs 'firewall' against official meddling in judicial cases
China configs 'firewall' against official meddling in judicial cases

Group criticizes Apple’s removal of IPv6 in Airport config tool
Back in January of this year Apple released AirPort Utility 6.0 , an updated version of the configuration tool for setting up home networks and ...

System Software: Configs for Mac 128K, XL, 512, & 512KE (7/94)
Macintosh 128K Currently ships with: Product no longer available. Supports: System 2.0 and Finder 4.1. Recommended: System 2.0 and Finder 4.1. ...

Free 32GB Apple TV and $60-$111 discounts on iMac 4Ks & iMac 5Ks, plus $150 coupons on all custom configs ...
Whether you want a free Apple TV plus discounts, a free AppleCare extended protection plan plus discounts, or just the lowest prices anywhere ...

Dell releases updated XPS-13 Developer Edition in wide variety of configs
... is available immediately in North America and Europe. According to Dell’s announcement blog post , there is a wide variety of possible configurations ...

Config error at Boston-area hosting company takes down Reddit, others
... hosting provider briefly knocked several large services and websites dependent on Amazon and AWS offline on Tuesday night, thanks to a configuration ...

Resources last updated: 2/19/2016 12:14:24 AM