How To Add Connectionstring In Web.Config Sharepoint 2010

Adding a connection string in the web.config file is essential for configuring and connecting SharePoint 2010 with various databases or external systems. To add a connection string in the web.config file for SharePoint 2010, you have a few options.

One option is to create a custom config list in SharePoint, where you can store key-value pairs for your connection strings. This provides a centralized location for managing and updating the connection strings.

Another option is to directly modify the web.config file and add the connection string under the <connectionStrings> section. This allows for more granular control and customization of the connection strings.

You can also use the property bag of the SPWeb object to store and retrieve connection string values. This provides flexibility in managing connection strings at the site level.

It is important to note that the web.config file for SharePoint is located in the virtual directories of the SharePoint web application, not in the layout folder. When adding the connection string, make sure to place it in the correct section of the web.config file depending on the requirements of your web part or application page.

By following these steps, you can successfully add a connection string in the web.config file for SharePoint 2010 and ensure seamless connectivity with your databases and external systems.

Options for Adding Connection String in SharePoint 2010

SharePoint 2010 offers multiple approaches for adding connection strings, including using a custom config list, directly modifying the web.config file, and utilizing the property bag of the SPWeb object.

One option is to create a custom config list in SharePoint, which allows you to store key-value pairs for your connection strings. This approach provides a centralized location for managing and updating your connection strings, making it easier to maintain and make changes as needed.

Another option is to directly modify the web.config file. By adding the connection string under the <connectionStrings> section, you can ensure that it is readily available for your web parts or application pages. However, it is important to note that the web.config file for SharePoint is located in the virtual directories of the SharePoint web application, not in the layout folder.

Additionally, you can utilize the property bag of the SPWeb object to store and retrieve connection string values. This option provides flexibility in terms of where the connection strings are stored and can be especially useful when you need to dynamically retrieve connection strings based on different conditions or configurations.

When adding a connection string, it is crucial to place it in the correct section of the web.config file to meet the requirements of your web parts or application pages. By carefully selecting the appropriate method and location for adding your connection strings, you can ensure optimal performance and functionality in your SharePoint 2010 environment.

Meet the Author

Abdul Rahim has been working in Information Technology for over two decades. Learn how Abdul got his start as a Tech Blogger , and why he decided to start this Software blog. If you want to send Abdul a quick message, then visit his contact page here.