I have this Sharepoint 2010 solution containing 3 projects:

  • Class Library with Model classes
  • Class Library with LINQ to SQL data context
  • Sharepoint 2010 project
    • WCF REST service
    • 3 Visual web parts
    • 1 package
    • 1 feature

I'm developing an installer that will run the PowerShell cmdlets to install the solution.

But I have some code in the feature's FeatureInstalled event that needs to create and initalize a SQL server 2008 database. The connection string to this server will be asked to the end user in the installer.

How can I pass this connection string to the solution in order to make use of it in the FeatureInstalled event?


Short answer: you can't. And why would you create the database using a feature? If you are creating an installer anyway, create the DB there using a db create script or a custom seetup action.

As for storing the DB connectionstring and or DB credentials: Use the SecureStore Service Application. See this article for information on how to configure the securestore and also the code needed for retrieving the values from it. An alternative is to store the the connection string in the webapp or site collection's PropertyBag.

P.S. Both options can be scripted using PowerShell

  • Yes, I guess I'll end up creating the DB in the installer. Thanks. – empz Apr 1 '12 at 17:20

You can create custom property for the feature. In your Feature CAML you can define

<Feature id...>
      <Property Key="ConnectionString" Value="String"/>

Then use this code in the feature receiver


In this case the user should modify feature CAML before activation. In this case the user should have access to the server folders...

In other case you can create configuration page, install it to the site, and create custom action for navigation button to this page. In this page you can run code that is locating in feature receiver now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.