I am writing a web site using asp.net mvc3 and in my website I want to have a page for setting capacity of a queue. this page is shared between some users. so I need to save this data somewhere which is reachable by all users. I do not like to store this value in Database because it is just a number and I prefer to save in another place.I also tried storing in file but it is not a good idea too because it need permission setting.
is there any other place than files on server which let me do this?
You are going to have to persist it somewhere if you want it to stay around, either a flat file or database or something similar.
Other than that, you can cache the value in memory (session, static, or another caching scheme) so you aren't constantly reading it from a heavyweight store. For example you could read it in on application start and then just use the in memory variable (writing it back to the disk when it changes).
Just create a table Settings with two columns Key and Value and reuse it for other settings you may need in the future.
Your database is a good place for storing your data - ie. database backups will backup your settings as well.
The alternative is using Configuration Manager.
NoSQL is a great option in this case, I think for this particular case Redis is a better fit, checkout Booksleeve from NuGet
Related
I'm just putting together an internal data system for a client, which is ASP.NET VB, backed by an SQL database, on an in-house IIS7.5 dedicated server.
I want to store certain global settings, such as the age limit for news articles, admin contacts etc, in a file NOT within the database (i.e. to avoid unnecessary database query's)
Where would the best place to store this be? global.asax? app.config? or a custom XML file? how would i import these at runtime? (probably to session variables)
ETA:
Also - the settings must be editable from within the site, i.e. an admin section i'm yet to build
If you need these settings to be editable, then the simplest place to store them would be in a database table. You're already building a layer to get in and out with CRUD operations, so adding this little extra won't hamper you. This will also help you keep your web.config clean and your supporting libraries will not need an extra app.config built into them.
Resource files and embedded app.config files are not editable so those preferred methods don't meet your requirements. You don't want people accessing the web.config directly (even through an interface) because changes to the web.config cause the application pool to recycle. A custom XML file would work, but you would have to build a separate parsing engine to get in and out of it. While this is simple, it would be unnecessary since you're already building an access interface for the rest of your database.
If you're really hating yourself though, you could combine the two into a custom xml file stored in the database as an XElement.
Thanks for your suggestions.
I decided the easiest method, given that the details may only need altering a couple of times a year, was to set session variables in global.asax
I am building an ASP.Net C# web application that will be using lots of sound files and image files. Considering performance, would it be best to store all files in SQL as image data type and retrieve from the database or store/archive the hard file on the server and store the path in sql? Im curious about the pros and cons - other than the obvious of storage space and manageability.
My current client is currently looking at the same options. There are a few tradeoffs to consider:
Storing as IMAGE data type:
You only need to backup your database rather than the DB and places on the file system
You don't have to worry about files being moved without the DB being updated with the new location or any other issues with hanging pointers to non-existent files
Storing as a file with a path in the DB:
Slightly faster access (we'll be quantifying this in the next few days)
Originally I thought that there would also be a problem with client-side caching of images. For example, when .NET gets the image out of the DB the client browser can't cache it - it looks like a new image every time. I then learned that unless you are giving users file-level access (a security no-no) you run into the same problem using direct file access.
From a performance perspective you should be better off storing the sounds/images as files and just keeping a reference to the location in the database. This will save you from having to transfer the data from the database to the web server and reconstitute the "file" via a handler whenever it is referenced. Of course, caching could help this but you'd still pay the penalty on each cache miss. This solution is also, for my money, somewhat less complicated in terms of the code that needs to be developed though you do have issues with collisions and some extra security setup (potentially) to do if you are enabling upload.
There are multiple values I have been storing in ASP.NET configSections sections for each "module". I have been wondering if they even belong in these files at all.
The background stands at: These are multiple instances of the web application deployed. All use the same database but have their own settings.
I'm sure that differences between development and production go in the config files. Some of the values I know should include: connection strings, providers to use, setting debug, etc.
I have factored out all the common pieces in to classes with their own rules and methods. The pieces left are miscellaneous settings for each module in each site. Some of the options I'm unsure of include:
For ModuleA, Show/Hide Option
For ModuleB, What is the terminology to be used for this field
For ModuleC, Allow end user to perform X action
Mmm these sounds like things that you might want be able to change at runtime for your application without having to modify the app.config. One rule of thumb I like to follow is that anything in the config should be for the deployment or server configuration. In this case your settings appear to be modifying the application behaviour and so I would probably move them into the DB if it is not alot of effort.
ModuleA and ModuleC sound like they may be user profile information. If they're not dynamic by user, but you could add later functionality, then maybe move them to a DB.
I've written apps where ModuleB would have been put in a DB also. Things like form labels, etc. can easily go in a DB. If, at a later date, someone decides to add or remove colons to all form labels, that's a pretty easy thing to do if all of the text is stored in a DB.
Consider the situation when you need to edit one of the values.
If the value is in web.config, saving the change to that file will cause the app to recycle, inconveniently throwing out current users. Not so much of a problem if your app is on an intranet only used during business hours (though you could get an angry call from the guy who stayed to work late). But potentially a problem on a public website with international users.
If the value is in a database, it will have no impact on the app's processing in that way.
Either way, consider whether the values are cached in the app's RAM (web.config is). Are the database values in an Application variable, or in Cache? If so, you may not know when the change will occur. Unless you want to restart the app.
And, what different access and permissions would the appropriate admins need to make the changes? Someone would have to have access to the web server(s) to change web.config, or to the database (and table) to change that.
A few questions: Why do you use the same DB for multiple instances of the application, and how will that effect maintanence?
In the future will it be an option to split the db in order to improve performance? Does the config model support that change better then the DB based one?
In other words, you will have to consider a lot variables in order to answer your question :-)
I have some configuration values for an asp.net web app. They will be maintained by a system admin once the system goes live. Should I store these values in the database or in a config file? Is there a best practice for this sort of thing?
It's easy and convenient to create a robust interface to edit the values in the database.
It's less easy to create a good one for the config file.
So I would usually you want to store everything which you would like your users/administrators to be able to edit later in the database. Everything which only needs to be touched during serious changes like re-installation etc is better off in the config file.
I would always recommend database simply because you can build an Admin UI relatively easy and audit all changes with similar ease. Although you can accomplish the same with changes to a file, the database route with some sort of a Admin control area is always preferable. Especially when you want to know who changed what when.
Also in our environment, changing a config file if there was an error, involves the entire change management process approvals/etc., which is pretty painful. So if you take the time to incorporate configuration settings in a database I think it will work out better in the long run. Just my $0.02.
I prefer a text config file, .ini style or XML style for these two reasons:
1 - You can put comments in the text file.
2 - Text editors have an "undo" command.
Depending on the context of the config information, you could choose to leave it in the web.config or you could create maintenance tables for it in the database. I would typcially keep things more backend specific, like connection strings, ftp locations, usernames/passwords(for the application, not user permissions) in the web.config though.
I normally keep more relative information that relates to the information in the database rather than the application itself, in the database.
This is all loosely based though and not always the case.
I prefer to avoid databases if I can and I don't need the performance. If you need/have a database then I would say put as much as you can in one place. One thing to manage.
I think databases are a great place for configuration values for distributed applications where you want a users settings to be available to them no matter which computer they use.
Configuration values stored in files are very useful for computer specific configurations (such as if you use a mapped drive to identify a location and every user may have a different mapping, like a CD/DVD drive for instance).
If you don't already have a database for the application you're developing though, it might be overkill to have a database exclusively for application configuration.
I prefer a text .ini file. They are easy to edit, and easy to move around when your application moves around. Here's an example Setting class that you may find useful.
I'm building an ASP .NET web solution that will include a lot of pictures and hopefully a fair amount of traffic. I do really want to achieve performance.
Should I save the pictures in the Database or on the File system? And regardless the answer I'm more interested in why choosing a specific way.
Store the pictures on the file system and picture locations in the database.
Why? Because...
You will be able to serve the pictures as static files.
No database access or application code will be required to fetch the pictures.
The images could be served from a different server to improve performance.
It will reduce database bottleneck.
The database ultimately stores its data on the file system.
Images can be easily cached when stored on the file system.
In my recently developed projects, I stored images (and all kinds of binary documents) as image columns in database tables.
The advantage of having files stored in the database is obviously that you do not end up with unreferenced files on the harddisk if a record is deleted, since synchronization between database (= meta data) and harddisk (= file storage) is not built-in and has to be programmed manually.
Using today's technology, I suggest you store images in SQL Server 2008 FILESTREAM columns (at least that's what I am going to do with my next project), since they combine the advantage of storing data in database AND having large binaries in separate files (at least according to advertising ;) )
The adage has always been "Files in the filesystem, file metadata in the database"
Better to store files as files. Different databses handle Blob data differently, so if you have to migrate your back end you might get into trouble.
When serving the impages an < img src= to a file that already exists on the server is likely to be quicker than making a temporary file from the database field and pointing the < img tag to that.
I found this answer from googling your question and reading the comments at http://databases.aspfaq.com/database/should-i-store-images-in-the-database-or-the-filesystem.html
i usually like to have binary files in the database because :
data integrity : no unreferenced file, no path in the db without any file associated
data consistency : take a database dump and that's all. no "O i forgot to targz this data directory."
Storing images in the database adds a DB overhead to serve single images and makes it hard to offload to alternate storage (S3, Akami) if you grow to that level. Storing them in the database makes it much easier to move your app to a different server since it's only the DB that needs to move now.
Storing images on the disk makes it easy to offload to alternate storage, makes images static elements so you don't have to mess about with HTTP headers in your web app to make the images cacheable. The downside is if you ever move your app to a different server you need to remember to move the images too; something that's easily forgotten.
For web based applications, you're going to get better performance out of using the file system for storing your images. Doing so will allow you to easily implement caching of the images at multiple levels within your application. There are some advantages to storing images in a database, but most of the time those advantages come with client based applications.
Just to add some more to the already good answers so far. You can still get the benefits of caching from both the web level maybe and the database level if you go the route keeping you images in the database.
I think for the database you can achieve this by how you store the images with relation to the textual data associated with them and if you can the access to the images into a particular query so that the database can cache the query (just theory though so feel free to nuke me on that part).
With the web side, I would guess since you're question is tagged up with asp.net that you would go the route of using a http handler to serve up the images. Then you have all the benefits of the framework at your disposal and you can keep you domain logic cleaner with only having to pass the key to your image to the http handler.
Here is a step-by-step example (general approach, Spring implementation, Eclipse) of storing images in file system and holding their metadata in DB --
http://www.devmanuals.com/tutorials/java/spring/spring3/mvc/Spring3MVCImageUpload.html
Here is an example too -- http://www.journaldev.com/2573/spring-mvc-file-upload-example-tutorial-single-and-multiple-files
Also you can investigate a codebase of this project -- https://github.com/jdmr/fileUpload . Pay attention to this controller.