SharePoint – Connection String dialog box during FeatureActivated event,
Does anyone know if it is possible to display a prompt to a user/administrator when activating or installing a sharepoint feature?
I am writing a custom webpart and it is connecting to a separate database, I would like to allow the administrator to select or type in a connection string when installing the .wsp file or activating the feature.
I am looking inside the FeatureActivated event and thinking of using the SPWebConfigModification class to actually write the connection string to the web.config files in the farm.
I do not want to hand edit the web.configs or hard code the string into the DLL.
If you have other methods for handling connection strings inside sharepoint I would be interested in them as well.
Unfortunately there is no way to swap to a screen where you can get user via the feature activation process. Couple of comments for you:
- I’m assuming the connection string is going to be different for every installation, so there is no way you can include it directly in the Solution.
- I’m assuming that you couldn’t programmatically construct this during installation.
Therefore, you need some way to get user input. Here are a couple of options:
- It could be a web part property, though this would mean setting it each and every time the web part was added, and you would need to then maitain those settings individually.
- You could build out your own _layouts settings screen (good post:, and from there users can maintain the property, storing it in either the Web Property bag, or inside the Web.Config. I try to avoid using the Web.Config where I can, but if you do wish to go this route then MAKE SURE you use the SPWebConfigModification class (Read this great blog:
- Finally, a technique I often use is storing configuration information in a SharePoint List. Chris O’Brien has a great framework for that here:
Hope that helps,
That’s the answer SharePoint – Connection String dialog box during FeatureActivated event, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.
The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you