0

I have a timer job that needs to connect to a SQL Database.

Where would one typically store this connection string.

In normal app development, one has app.config. Clearly using app.config in this scenario is not the right place for the configuration to be stored.

Ideally I'm looking for a way the user can change the connection string.

Do I need to create a custom list, or is there a proper way to store configuration such as this connection string?

2 Answers 2

1

I have posted a viable option and few pointers here.

1

you could use a list, or another way is to use SPWebConfigModification to store the string you need into the appsettings node of web.config on feature activation, and just use the AppSettings property bag to access it.

The benefit of SPWebConfigModifications are that the the changes are affected to multiple web-front ends if you have many, otherwise you can make a static change to the web.config directly if you're in dev, or only have one web frontend.

3
  • Problem I have with SPWebConfigModification, is it would theoretically cause the web application in IIS to restart if it is modified. Are you 100% sure there isn't a built in way to manage configuration for timer jobs natively in SP2010?
    – user879
    Commented Dec 8, 2010 at 8:50
  • Could have a look at SPPersistedObject - create a class which represents the configuration for your timerjob and inherit from SPPersistedObject.
    – James Love
    Commented Dec 8, 2010 at 9:08
  • I discovered that the SPJobDefinition has a properties collection. This can be set during feature activation where you define the job. But I'm trying to find out how to expose this to a sharepoint admin via central admin.
    – user879
    Commented Dec 8, 2010 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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