How to change ConnectionString dynamically in C#
Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "DynamicallyConnectionString" and then click OK
Step 2: Design your form as below
Step 3: Add a connection string to the app.config file as below
1
2
3
4
5
| <configuration> <connectionStrings> <add name="cn" connectionString="Data Source=.;Initial Catalog=Northwind;User ID=sa;Password=123@qaz?;" providerName="System.Data.SqlClient"/> </connectionStrings></configuration> |
