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

    How to change the connection string dynamically in VB.NET

    i have written my connection string in app.config (in configuration. appSettings).
    when a user login, there is a form called user setting, where the user can change the database name or datasource. so that when the user login next time he login by the new connection string.

    tell me where to keep this new setting and how to change the connection string.
    Please write the code in VB.Net.
  • #587169

    create one table domain which contain database name and user name and password .

    Let user login using default configuration

    when user is success get the detail from domain table and store the username password database in session

    You need to change the access of configuration in every page

    declare conn as global ;

    assigh the value to the conn inside the pageload event as first line
    conn="your connection string " databasename ="sessiondatabasename",user="sessionuser",pass="sessionuser";

    i have use this in c# application only so you may get idea through this code

  • #587193
    Sisnce each user can have thei connection string , the best way is to store them in database.

    Have a primary database , when ser logs in you always connect to this database to authenticate the user. Once user is authenticated read the connection string form the primary database an connect to user specific database.


  • #587199
    Thanks for ur post Sethu.
    what i want is :
    i want to keep that connection details in that machine itself in any file in encrypt way.
    application will first search this file if not found, then go for the default connection.

  • #587210
    try this code

    Imports System.Configuration
    Imports System.Web.Configuration

    Dim Config1 As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
    Dim conSetting As ConnectionStringsSection = DirectCast(Config1.GetSection("connectionStrings"), ConnectionStringsSection)
    Dim StringSettings As New ConnectionStringSettings("ConStringName", "Data Source=ServerName;Database=DataBaseName;User ID=sa;Password=12345;Integrated Security=True; Pooling=false;Connect Timeout=120;")

    hope this will help you

  • 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.