0

I'm using SQL Server 2008. I need to Enter the connection details through a windows form and save the connection details in a file.

The issue is, I need to use the same credentials for other forms without embedding the credentials in the code. Other forms should retrieve the connection details. In short, once the credentials are saved, other forms should also be able to use them without re-entering the credentials again and again

The question is, How do I do this?

Save Form

Draken
  • 3,134
  • 13
  • 34
  • 54
Varun
  • 1
  • 2
  • You could persist these informations in a file. The content that has to be written and read to a file should come from a [`SqlConnectionStringBuilder`](https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.aspx). – Oliver May 10 '17 at 05:54
  • Possible duplicate of [how to define a connection string using an app.config file in C#](http://stackoverflow.com/questions/20871776/how-to-define-a-connection-string-using-an-app-config-file-in-c-sharp) – Chandan Kumar May 10 '17 at 06:02

2 Answers2

0

You can accomplish what you're looking for by storing the connection string in your app.config.

You can check out this article on storing custom values in the app.config which would be a good strategy if there are individual values that you want to store and then you want to dynamically build the connection string.

If you prefer to just store and retrieve the complete connection string then you can check out this article.

Community
  • 1
  • 1
Dan Siegel
  • 5,724
  • 2
  • 14
  • 28
0

Varun (I am assuming that you are able to write source code to read and write files using c#) to solve this problem you need to do 2 tasks in the form load event.

  1. Check if the file containing your login credentials already exists at your desired location then read the file and fill the relevant details in the text boxes accordingly.
  2. If the file does not exists then create the new file at a specific location of your choice with credential details.

So whenever the user opens the login form it's form_load() method will work accordingly based on above two conditions.

Apart from this, if you don't want to do this you can use your app.config file for the same job.