state management

Hi all!!

I'm newbye in c#.

I'm looking state management for web apps. I read about web.config, Application[".."], Session[".."], ViewState...

It's OK. My question is:

I'm writing a web user control and i need to expose a connection (to DB) or a connection string. It's a sensible data! How can store it in my control I''m using Session["..."]. Is it correct (i'm not using web.config because it changes from app to app and i'm writing user control!) What are you using in your applications Are there other methods

Thanks,

Regards,

Ema




Answer this question

state management

  • REasley

    Maybe you not have understood...

    i have a user control and i don't know which type of Db i'm using(it depends from app).

    So i need connection/conn string as property.

    I understood what you told me but i need the connection string else how can i connect to DB My user control is indipendent from the DBtype...I have user control and a DBmanager (the DAL) that open and close connection and do query.

    If i'm wrong, sorry....i'm trying to understand



  • bwechner

    pls, i'm noob...explain better: i can't understand your code.

    My user control has an user interface and code behind, so it could be insert into a page! My user control show a list got from a DB but it doesn't know which type of DB is.

    So i need a connection or a connection string as a property.

     



  • kef_c80

    Ema,

    I think you can store it in session or application variable.

    Regards,

    venkataraman.R


  • TaDa

    You create a DAL (Database Access Layer), you can find a lot of information on that one.

    Then you create you the classes you need, when you want to display Customer's on you UserControl make a Customer class and a CustomerCollection class.

    The only thing you need to do then is give you UserControl a property that can take a CustomerCollection and uses that for displaying.

    When you want to fill you UserControl with stuff from the database, just fill the property.

    So in my example the CustomerRepository.FindAll(), looksup the database and returns a CustomerCollection class filled with all available Customers.



  • Jo Molnar - MSFT

    Why should a UserControl use a Connection string. Then it isn't reuseable. Just give the UserControl properties to set what you want to view.

    // Get the customers from the database and give them to the UserControl
    MyUserControl.Customers = CustomerRepository.FindAll();



  • state management