Best way to maintain settings?

R

Ronald S. Cook

We have a .NET Win app that runs at 12 different cattle feeding lots. Each
lot runs an isolated instance of our app using its own SQL Server instance.

For overall settings specific to a feedlot, we're maintaining those values
right now in the database. But I'm not sure its the best way to do it. You
see, we have a table "tblFeedlot" with about 20 columns BUT then only one
record in the table.

I thought maybe the table should have just two columns "Name" and "Value" to
and have 20 records, but then the datatype would have to be varchar(100) I
suppose and we'd have to d alot of validating/converting. But maybe this is
the better way to go?

Or do you recommend another way? Would there be some sort of app.config
specific to each feedlot that we stored somewhere?

Thanks,
Ron
 
N

Nicholas Paldino [.NET/C# MVP]

Ron,

The app.config file is exactly what you should be doing. You can set
the values you need in the app.config file, and then read them easily.
 
R

Ronald S. Cook

But the same app is installed at 12 sites and each site's specific values
must be retrieved and used. I wouldn't think we'd maintain a separate
app.config for each feedlot. Or should we?

Thanks,
Ron


Nicholas Paldino said:
Ron,

The app.config file is exactly what you should be doing. You can set
the values you need in the app.config file, and then read them easily.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ronald S. Cook said:
We have a .NET Win app that runs at 12 different cattle feeding lots.
Each lot runs an isolated instance of our app using its own SQL Server
instance.

For overall settings specific to a feedlot, we're maintaining those
values right now in the database. But I'm not sure its the best way to
do it. You see, we have a table "tblFeedlot" with about 20 columns BUT
then only one record in the table.

I thought maybe the table should have just two columns "Name" and "Value"
to and have 20 records, but then the datatype would have to be
varchar(100) I suppose and we'd have to d alot of validating/converting.
But maybe this is the better way to go?

Or do you recommend another way? Would there be some sort of app.config
specific to each feedlot that we stored somewhere?

Thanks,
Ron
 
N

Nicholas Paldino [.NET/C# MVP]

Ronald,

Yes, you would have a separate app.config file for each feed lot.
That's the whole point, this is where you would differentiate in the
settings. Basically, your configuration file would look like this:

<configuration>
<appSettings>
<add key="SomeKey" value="SomeValueForFeedLot1" />
</appSettings>
</configuration>

At another feed lot, you would have:

<configuration>
<appSettings>
<add key="SomeKey" value="SomeValueForFeedLot2" />
</appSettings>
</configuration>

And so on. Granted, you could write a configuration section handler,
but for something like this, this would do just fine, I think.

Then, to access these values in code:

// Get the "SomeKey" value:
string someKeyValue = ConfigurationManager.AppSettings["SomeKey"];

This will require a reference to System.Configuration.dll and this .NET
2.0-specific. In .NET 1.1 and before, you can do the same thing in the
app.config file but use this:

// Get the "SomeKey" value:
string someKeyValue = ConfigurationSettings.AppSettings["SomeKey"];


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Ronald S. Cook said:
But the same app is installed at 12 sites and each site's specific values
must be retrieved and used. I wouldn't think we'd maintain a separate
app.config for each feedlot. Or should we?

Thanks,
Ron


Nicholas Paldino said:
Ron,

The app.config file is exactly what you should be doing. You can set
the values you need in the app.config file, and then read them easily.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ronald S. Cook said:
We have a .NET Win app that runs at 12 different cattle feeding lots.
Each lot runs an isolated instance of our app using its own SQL Server
instance.

For overall settings specific to a feedlot, we're maintaining those
values right now in the database. But I'm not sure its the best way to
do it. You see, we have a table "tblFeedlot" with about 20 columns BUT
then only one record in the table.

I thought maybe the table should have just two columns "Name" and
"Value" to and have 20 records, but then the datatype would have to be
varchar(100) I suppose and we'd have to d alot of validating/converting.
But maybe this is the better way to go?

Or do you recommend another way? Would there be some sort of app.config
specific to each feedlot that we stored somewhere?

Thanks,
Ron
 
R

Ronald S. Cook

Thanks for the advice, Nicholas. I should have mentioned, though, that
through the application, the values will need to be updated. I think this
forces the data back to the database.

Assuming you agree, do you like one record with many columns, or just
key/value columns and many records in a table.

Thanks for the responses,
Ron


Nicholas Paldino said:
Ronald,

Yes, you would have a separate app.config file for each feed lot.
That's the whole point, this is where you would differentiate in the
settings. Basically, your configuration file would look like this:

<configuration>
<appSettings>
<add key="SomeKey" value="SomeValueForFeedLot1" />
</appSettings>
</configuration>

At another feed lot, you would have:

<configuration>
<appSettings>
<add key="SomeKey" value="SomeValueForFeedLot2" />
</appSettings>
</configuration>

And so on. Granted, you could write a configuration section handler,
but for something like this, this would do just fine, I think.

Then, to access these values in code:

// Get the "SomeKey" value:
string someKeyValue = ConfigurationManager.AppSettings["SomeKey"];

This will require a reference to System.Configuration.dll and this .NET
2.0-specific. In .NET 1.1 and before, you can do the same thing in the
app.config file but use this:

// Get the "SomeKey" value:
string someKeyValue = ConfigurationSettings.AppSettings["SomeKey"];


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Ronald S. Cook said:
But the same app is installed at 12 sites and each site's specific values
must be retrieved and used. I wouldn't think we'd maintain a separate
app.config for each feedlot. Or should we?

Thanks,
Ron


Nicholas Paldino said:
Ron,

The app.config file is exactly what you should be doing. You can set
the values you need in the app.config file, and then read them easily.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

We have a .NET Win app that runs at 12 different cattle feeding lots.
Each lot runs an isolated instance of our app using its own SQL Server
instance.

For overall settings specific to a feedlot, we're maintaining those
values right now in the database. But I'm not sure its the best way to
do it. You see, we have a table "tblFeedlot" with about 20 columns BUT
then only one record in the table.

I thought maybe the table should have just two columns "Name" and
"Value" to and have 20 records, but then the datatype would have to be
varchar(100) I suppose and we'd have to d alot of
validating/converting. But maybe this is the better way to go?

Or do you recommend another way? Would there be some sort of
app.config specific to each feedlot that we stored somewhere?

Thanks,
Ron
 
N

Nicholas Paldino [.NET/C# MVP]

Ronald,

I don't necessarily agree. It depends on how often those values are
updated.

If the values are ones that are not user-controlled, meaning that you
set them and change them when necessary, then the database is the wrong
place for this, it should be in the app.config file.

If the values are user-controlled, and changed with any sort of
frequency, then yes, the database is the better place. I would most likely
have a table with typed columns for specific values. It's easier to perform
other operations in the database than if you had a table with a key/value
pair.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ronald S. Cook said:
Thanks for the advice, Nicholas. I should have mentioned, though, that
through the application, the values will need to be updated. I think this
forces the data back to the database.

Assuming you agree, do you like one record with many columns, or just
key/value columns and many records in a table.

Thanks for the responses,
Ron


Nicholas Paldino said:
Ronald,

Yes, you would have a separate app.config file for each feed lot.
That's the whole point, this is where you would differentiate in the
settings. Basically, your configuration file would look like this:

<configuration>
<appSettings>
<add key="SomeKey" value="SomeValueForFeedLot1" />
</appSettings>
</configuration>

At another feed lot, you would have:

<configuration>
<appSettings>
<add key="SomeKey" value="SomeValueForFeedLot2" />
</appSettings>
</configuration>

And so on. Granted, you could write a configuration section handler,
but for something like this, this would do just fine, I think.

Then, to access these values in code:

// Get the "SomeKey" value:
string someKeyValue = ConfigurationManager.AppSettings["SomeKey"];

This will require a reference to System.Configuration.dll and this
.NET 2.0-specific. In .NET 1.1 and before, you can do the same thing in
the app.config file but use this:

// Get the "SomeKey" value:
string someKeyValue = ConfigurationSettings.AppSettings["SomeKey"];


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Ronald S. Cook said:
But the same app is installed at 12 sites and each site's specific
values must be retrieved and used. I wouldn't think we'd maintain a
separate app.config for each feedlot. Or should we?

Thanks,
Ron


in message Ron,

The app.config file is exactly what you should be doing. You can
set the values you need in the app.config file, and then read them
easily.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

We have a .NET Win app that runs at 12 different cattle feeding lots.
Each lot runs an isolated instance of our app using its own SQL Server
instance.

For overall settings specific to a feedlot, we're maintaining those
values right now in the database. But I'm not sure its the best way
to do it. You see, we have a table "tblFeedlot" with about 20 columns
BUT then only one record in the table.

I thought maybe the table should have just two columns "Name" and
"Value" to and have 20 records, but then the datatype would have to be
varchar(100) I suppose and we'd have to d alot of
validating/converting. But maybe this is the better way to go?

Or do you recommend another way? Would there be some sort of
app.config specific to each feedlot that we stored somewhere?

Thanks,
Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top