Modify the connection string used by the tableadapter in memory

Last post 10-27-2009 8:24 AM by elburs. 6 replies.

Sort Posts:

  • Modify the connection string used by the tableadapter in memory

    10-23-2009, 7:28 AM
    • Member
      6 point Member
    • elburs
    • Member since 01-21-2008, 12:11 PM
    • Posts 57

    Hello

    I use the table adapter in Visual Studio 2008 to access database, and my application has several databases, all duplicated with  the same structure (same tables and same stocked procedures)

    I have web services wich will point at a specific database by looking the parameter in the web service

    I can't put several connection strings in the web.config file, and i don't want to

    and i don't want to pass the connection string in parameters of all methods to the DAL

    I would like to modify in the web service directly the connection that the DAL will use , in the context of this web service

    so that i don't have to change my DAL and modifiy the "Connection" property on my table adapter

     

    i tried this :

    Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Web.config");
    config.ConnectionStrings.ConnectionStrings[0].ConnectionString =;"Data Source=PC22;Initial Catalog=TEST;User ID=sa;Password=sa";


    but it won' work because it's read only

  • Re: Modify the connection string used by the tableadapter in memory

    10-26-2009, 2:17 AM

    Hi elburs,

    I may not understand your question clearly, but I don't think you can do it like that. When using typed dataset, you can't change the connection string anymore except to modify the connection string in web.config. But it can't be modified in source code since it's readonly. I don't know why you can't modify it in web.config, but it's the mormal way we do.

    Thanks. 

    David Qian
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Modify the connection string used by the tableadapter in memory

    10-26-2009, 3:06 AM
    • Member
      6 point Member
    • elburs
    • Member since 01-21-2008, 12:11 PM
    • Posts 57

    i cant because the connection string depends on the user connected, i will create that with business rules and by calling a web service provided by my firm

    it has to be dynamic

  • Re: Modify the connection string used by the tableadapter in memory

    10-27-2009, 1:41 AM

    elburs:
    i cant because the connection string depends on the user connected,

    Then can't you modify the connection string content in web.config? Thanks.

    David Qian
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Modify the connection string used by the tableadapter in memory

    10-27-2009, 6:05 AM
    • Member
      6 point Member
    • elburs
    • Member since 01-21-2008, 12:11 PM
    • Posts 57

    no i have just explained there are many connection strings, one by user so a lot of connection strings possibles, and depending on the user connecter

     

    all my web services take a user id in parameter, with this, i call another web service which will give me the connection string to use for this user

    so i cant modify the web .config because

    - It can't be modified it's read only

    - even if it was possible, there could be locks because several web services could open and save it at the same time

    - i dont have to pollute the file and i want to have it in memory

    - it's not performant to write and read from a file each request being called

  • Re: Modify the connection string used by the tableadapter in memory

    10-27-2009, 6:11 AM
    • Member
      188 point Member
    • binli0114
    • Member since 09-26-2006, 12:31 AM
    • Sydney
    • Posts 48

    I am wondering why you don't put the connection strings either in Session or Cache

    ------------------------------------------------------------
    I LOVE THIS GAME
  • Re: Modify the connection string used by the tableadapter in memory

    10-27-2009, 8:24 AM
    • Member
      6 point Member
    • elburs
    • Member since 01-21-2008, 12:11 PM
    • Posts 57

    - session doesn't exist in WCF, only asp.net, but this is what i want

    - cache is common to all the application, and i want for one request only, only the context of the thread, the lifetime of the wcf request

Page 1 of 1 (7 items)