1

I am using Quartz .net with an AdoJobStore jobStore. In the .config file, there is a property that is used to set the connection string:

<add key="quartz.dataSource.default.connectionString" value="Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=True" />

However, I manage all my connection strings in a separate config file, so I currently need to dupplicate this connectionString information.

Is there a way to not specify the quartz.dataSource.default.connectionString in the .config file and manually set it via code, so I can get my value in my global connectionStrings config file?

It seams that it is possible to use a NameValueCollection when instanciating a StdSchedulerFactory, but I don't want to manage all settings, only the connectionstring.

Normand Bedard
  • 2,625
  • 2
  • 19
  • 22

2 Answers2

1

In the end, they are all simply named-value pairs.

You can have "most" of them in an .xml file...then "add in" the ones you want via code.

Or have all of them in code.

See the UnitTests for the source code, and you'll see this fairly clearly.

Something like this:

    NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("quartz");

    config.Add("MyCodedUpKey", "MyCodedUpValue");

I would NOT put

"quartz.dataSource.default.connectionString"

in your .xml file...to avoid a collision..... Or you can write extra logic to remove and add to the NameValueCollection .

Or take a peek here:

Check if Key Exists in NameValueCollection

Community
  • 1
  • 1
granadaCoder
  • 26,328
  • 10
  • 113
  • 146
  • 1
    It's easy to avoid a collision in the NameValueCollection. Just use `config.Set("MyCodedUpKey", "MyCodedUpValue")`, which will replace the value in there if the key exists or add the key with the value if it doesn't. – saluce Apr 23 '14 at 21:34
  • You're right! http://msdn.microsoft.com/en-us/library/system.collections.specialized.namevaluecollection.set%28v=vs.110%29.aspx – granadaCoder Apr 23 '14 at 21:42
0

Finally fix my problem by passing all the configuration attribute using code, but by parsing the quartz config to get them automatically.

And I manually add the quartz.dataSource.default.connectionString property at the end and setting the value by getting it in my global connectionStrings.config file.

Normand Bedard
  • 2,625
  • 2
  • 19
  • 22