Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7744799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:51:16+00:00 2026-06-01T09:51:16+00:00

I have an application that consists of two forms. One form displays data returned

  • 0

I have an application that consists of two forms. One form displays data returned from the database in fields and the other form opens a windows that allows the user to select which database to get the data from.

Currently, the application doesn’t store the user’s choice of database. I want to store what the currently selected connection string is each time the user selects the database they want to use in form2.

What is the best way to do this? If I made an instance of an object of a static class to store this information, would that persist the data for use on each form?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:51:18+00:00Added an answer on June 1, 2026 at 9:51 am

    Though there are built-in .NET capabilites to store user related information (via Registry, config files, settings etc.) they seem to be too heavy.

    I would recommend to use plain text file and keep it in user folder:

    var userPath = Environment.GetFolderPath(Environment
                                                 .SpecialFolder.ApplicationData);
    var filename = Path.Combine(userPath, "mysettings");
    
    // Read connection string
    var connectionString = File.ReadAllText(filename);
    
    // Write connection string
    File.WriteAllText(filename, connectionString);
    

    Also note that hardly users will have fun working with connection strings. They would prefer to specify database name, server, username etc. using separate form fields. To map those fields to connection string you may use SqlConnectionStringBuilder class (if you are working with MSSQL Server):

    // to connection string
    var connectionStringBuilder1 = new SqlConnectionStringBuilder();
    connectionStringBuilder1.DataSource = "server";
    connectionStringBuilder1.InitialCatalog = "database";
    var connectionString = connectionStringBuilder1.ConnectionString;
    
    // from connection string
    var connectionStringBuilder2 = new SqlConnectionStringBuilder(connectionString);
    var serverName = connectionStringBuilder2.DataSource;
    var databaseName = connectionStringBuilder2.InitialCatalog;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that consists of two websites - one running on
Suppose you have an application that consists of two layers: A: A data layer
I have an application that consists of two processes (let's call them A and
I have an application that displays an image inside of a Windows Forms PictureBox
I have wrote an application that consists of two projects in a solution, each
I have this application that consists of two phases. Queuing phase and chatting Phase.
I have an application that shows data from a MySQL table. Basically, my application
I have a server application that consists of multiple OSGi bundles, some mine, some
I have a solution that is deployed using ClickOnce. It consists of an application,
I have an application that reads a CSV file with piles of data rows.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.