You must Sign In to post a response.
  • Category: ASP.NET

    Changing databases at runtime in asp.net

    I have an application that requires that User A connects to Databases DB1,DB2,DB3 and so on to do simple CRUD operations...Is it possible in Asp.net 3.5 to change the databases at runtime so that User A can select the database he wants from, say a DropDown list ,at runtime? ...I am using VS 2008 and C#...
  • #583510
    hi you can change web.config file at runtime for that this code is useful



    using System.Configuration;
    using System.Web.Configuration;

    Configuration Config1 = WebConfigurationManager.OpenWebConfiguration("~");
    ConnectionStringsSection conSetting = (ConnectionStringsSection)Config1.GetSection("connectionStrings");
    ConnectionStringSettings StringSettings = new ConnectionStringSettings("ConStringName", "Data Source=ServerName;Database=DataBaseName;User ID=sa;Password=12345;Integrated Security=True; Pooling=false;Connect Timeout=120;");
    conSetting.ConnectionStrings.Remove(StringSettings);
    conSetting.ConnectionStrings.Add(StringSettings);
    Config1.Save(ConfigurationSaveMode.Modified);



    hope this will help you
    and you can see my code snippets in DNS for that link is below

    http://www.dotnetspider.com/resources/40019-Change-Connection-String-Web-config-at-RunTime.aspx

  • #583513
    Hi,

    Yes it is possible, there is a nice article in below link, just go through it for step step explanation,

    http://www.aspfree.com/c/a/MS-SQL-Server/SQL-Connection-Connecting-to-Multiple-Databases/


    Regards,
    Asheej T K


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.