check this link how to secure connection string
Add Connection String to Web.confif/App.config
- Open an .aspx page in Design View in Visual Studio.
- From the Toolbox, from the Data folder, drag a data source control, such as a SqlDataSource control, onto the design surface.
- Right-click the control, and click Show Smart Tag.
- In the smart tag panel, click Configure Data Source.
- In the Choose a Data Connection panel, click New Connection.
- Select an appropriate data source from the list on the Choose Data Source dialog box, and then click OK.
- Indicate the correct server name, user name, and password on the Add Connection dialog box, and then click OK. You are returned to the Configure Data Source dialog box with a summary of your connection details.
- Click Next, and then click Yes to save your connection string in the Web.config file.
To encrypt connection string information stored in the Web.config file
aspnet_regiis -pe "connectionStrings" -app "/SampleApplication"
For more details check the link shared above