Storing images in SQL Server using C# [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I want to store images of my employees with their profile details in SQL in a SQL Server database, but I have following reservations:
Should I compress images or not and if yes, please can the community provide me sample code or direct me to a guide that can assist me with this.
How should I retrieve images efficiently? I am afraid of asp.net application performance issues. I think with thousands of employee records, the system may halt or slow down.

I would suggest storing the path of the images on your sql table, and actually store the image in a secure folder. This has worked for me perfectly.

Sql Server is well equipped to handle large amounts of binary data, but as always, the devil is in the details and the design:
To avoid any performance issues that can happen with reporting or access from other applications due the Sql Server's paging process (all db engine use pages as a discrete unit of data manipulation) I would place the image data in a separate table that is linked 1-to1 to your employee table. Doing so will keep the binary data from being moved around with employee queries unnecessarily when accessed from other parts of your system. Your image display logic will of course have to join on the two tables to match up employee and image records.

First thing, ten thousand records is nothing ... as long as you have the right indexes in place SQL Server will handle that with ease.
However, consider just using the file system to store things like images. The SQL Server record could just contain a pointer (ie. path) to the file and the asp.net application could just use that to read the file from disk and stream it to the browser.

Most image formats (such as JPEG, or PNG) already employ some compression algorithm, so unless your source is a RAW image or an uncompressed bitmap, additional compression won't help much. What might help is limiting the size of the image, say a maximum of 400 x 400 pixels. I don't know what the intended purpose is so I don't know if this will work well for you. Obviously, if you are storing the data directly from a digital camera, the images will be very large and you might want to scale them down first, to something more reasonable.

If you are on SQL server 2008 or above then you can use the filestream feature that is like the best of both worlds. It stores the image in the filesystem but has it under transactional control and is also included in your backups when they are taken.
If you are not on 2008 or above then I would say to keep the images in the DB, see this old Microsoft white paper for my reasons why.
http://arxiv.org/pdf/cs.DB/0701168

Related

Using JSON file as database in a ASP.NET App(C#) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 months ago.
Improve this question
I am developing a light weight web app in ASP.NET with C# and I would like to store some data such as site analytics etc.
Instead of using a SQL server database could I use a JSON file instead? So I would open the JSON file and write into it when done. Could there be problems with simultaneous connection?
Is this standard/ common practice?
Any help will be highly appreciated.
It is probably a VERY bad idea. I would only do this if it was some text file to display a wee bit of information.
If you need updating? Then what happens if two users are on the site. The last person to update will over write the text based json file.
I suppose you could write out a "id" and json file for each record you edit, and that way a save of one record value would not over write others. But, putting more then one reocrd in a json file, and if users are to edit such values, then no, it will not work, since a simple save of that text json file will overwrite any other changes made by any other user who also happens to hit the same button.
It is VERY hard to find a web site hosting, even those for super cheap - less then $10 per month that does not include a database server system. And be it MySQL, SQL server, postgres sql and more? They all have free verisons you can use.
And I suppose you could consider the file based sqlLite. That would even be better. While it not considered thread safe, it can work if you only say have a a few users like 2-4 users working at the same time.
Because you have OH SO MANY choices here? The only reason to use a text based json file is if no other options exist - and boatloads of options exist in near all cases.
And if some database was not available? The I would simple include sqlLite in the project and use that.
I'm not super experienced but i would like to explain why i would never do that.
First of all everything (if you are brave enough) can be a database, as long as it is some kind of file that can give persistency to your data. Database are basically optimized one purpose software to store data. Mainly the problem in your solution is that you would need to read the file and load it in memory storing it as an object and then writing data to it like you would do with a static factory object and then serialise it back to JSON after you are don with it. Personally i don't like this idea because i think is very prone to human error (like deleting the file by accident during mantainance) and it can be hard-er to debug if it starts accumulating a sizeable chunk of data. There are very lightweight data persistency solutions that implements SQLite that is a database for small applications, like Pocket Base. Since you are already developing a backend it would require you near to no effort to add a little table to store the analytics.

How to maximize SQL retrieval of binary images [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am creating a Zillow-like IOS app. I am using Azure SQL (S-0 version) and C# for my backend. I store users data including the avatar of each user and the trips the person has been to (another table), where each user can have multiple trip pictures. I am using varbinary(max) to store those image types. So each user entity would have an average of 3 pictures.
my C# app retrieves all users with all their images and trip info and images using lazy loading in my linq-to-sql query.
The issue is naturally the time it takes to load all those date before user becomes able to consume it in the iphone clients (written in Swift). The end user will need all data to scroll through all those images. He at first load users, to see his images and read about him, and then scrolls up and would see trips the other user has gone to. It won't make sense for the user to see only avatars and then wait for all trips for example, every time he calls.
What strategy should I do to minimize the load time!?
The thoughts I have had so far:
Use Azure Blobs to store images and consume that right from my swift clients to see if it will be any faster. I ditched that option because the extra slow retrieval of files because I have to first access the image file from my C# code, and make binary out of it so I can transmit it to my iphone client app.
Instead of using linq-to-sql, use the good ole ADO.NET to minimize the extra layer linq-to-sql. I didn't see much difference not even a second extra.
optimize my linq query by adding as much as possible in the where clause and avoid using loops. Make them all one select statement. The query spat by the linq-to-sql seems right. It didn't change much because the issue is the extra huge binary write ups being retrieved.
I mentioned it already above, using silent calls where I load only the user-related image and then when user sees summary, behind the scene I start loading all those trips, but the user will quickly need to check the trips. He will be confronted of having to wait again to see those trips. And I would have to initiate new calls to DB, which is expensive. Very undesirable!
What other suggestions should I try?

C#: methode for storing large and complex data? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am trying to store a software "Calender"(complex logs that saved and browsed based on date).
I tried using both .ini and xml but when the application tried to read the entire file to find info for 1 specific day out of the 100 days (or so it seemed), it took almost 9 seconds to get 5 variables out of 500 variables. The size of the actual file might eventually be more than 40 variables per day.
Also, I would rather not make a file for each day, that will seems a little bit unprofessional and messy.
I am asking the question to know if there is an alternative to keep things fast and neat. The data includes different types of variables and different amounts of them. I know i am kinda overdoing it with logging thing but the program needs logs to do its work
If the data must be stored it has to be a file or a database (local or remote), I'd go for SQLite, it would end in a single file, but you could query the data with SELECT, JOIN, etc.
EDIT:
You can use SQLite3 from c# if you include this package:
https://www.nuget.org/packages/System.Data.SQLite/
You'll need to learn some SQL, but after that you'll just use something like:
select Message from Logs where Date > '2015-11-01' and Date < '2015-11-25';
which is easier, faster and clearer than messing with XML, and it will not load the whole file.
As mentioned above, SQLite will offer a great possibility. Since you (generally), and probably not a lot of people out here will be able to write a database management system that is as efficient as the ones out there.
https://www.sqlite.org
Whole point of using RDBMS because it's far more efficient that dealing with files.
SQL Lite is light weight and easier to deploy. But remember that,
SQLite only supports a single writer at a time (meaning the execution
of an individual transaction). SQLite locks the entire database when
it needs a lock (either read or write) and only one writer can hold a
write lock at a time. Due to its speed this actually isn't a problem
for low to moderate size applications, but if you have a higher volume
of writes (hundreds per second) then it could become a bottleneck.
Reference this question
If this is an enterprise level application requirement I would go for Azure Table storage based solution which is identical for this sort of scenario.

Creating a program for Volunteers, how should I store the data?(xml, sql, etc) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Disclaimer: Yes, I am fairly new to storing data in files. But this is something I'm willing to learn, and take the time to learn
I am working on creating a program for someone who keeps track of volunteers and how much time they spend working, and what they are working on.
For each volunteer I will have their Address Information, email, phone, etc. I will also have what show they worked, how long they worked it for, and what position they were working.
Later, the user will be able to access a way to print out monthly reports of this information.
I am wondering if anyone is willing to give me a nudge in the right direction. How should I store all this data? I've heard of XML, SQL, JSON, and other things here and there. I need something that can handle large amounts of data, as there are about 200 volunteers right now, and data will need to be constantly added to this file(s). Are there any suggestions? If you need me to clarify something, please just ask.
Also, I am using Windows Forms Application, C#.
There are different ways to accomplish this, most preferred ones would be either SQL database (MySQL, MSSQL, SQLite, etc.), JSON storage (and GZipping, for good measures. Saving storage, you know), or binary storage (aka. knowing the complete size of the data you're storing, such as how many Int32's, and reading this in bytes from a file).
I'd go with the JSON storage if you're not planning on accessing this data from more than 1 computer.
If portability is what you want, you're gonna want to go with SQL.
If you're just looking for a simple way to store data, then it'd be either JSON or binary saving.
These are probably the best choices you have, on how to save data.
#Edit: Seeing how you've specified large amounts of data, your best shot would be either SQL or Binary. Binary, because you can jump around in files because you know the size of each object, so you wont have to read all of them. SQL because it has this feature built as part of the core. Json simply wont be a very good choice for large amounts of data.
XML, you're gonna want to avoid entirely, unless you want to be able to export data because other applications requires it in XML format. XML simply uses too large amounts of storage space, due to the whole structure of the language.
#Edit2: Would whoever downvoted my answer, explain why please? .__.'
SQL can handle pretty much a lot of data. It is easy to use for a beginner and there is a lot of support for it.

Save image in database directly or to save image path? SQL SERVER [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am using C# .NET v3.5, SQL SERVER 2008. My team is creating Point Of Sale Windows Application for Restaurant and Super Markets, so there will be a huge amount of pictures in the application. For which, I want to know which will be better in terms of responsiveness, saving the images directly in database or to save image paths in the database.
I'll appreciate your response.
Thank you!
Sarmad Asif
As of me Save Image in paths will be better.
I already gone through these phase. We develop Jewellery Software in which we also have huge amount of image. We first store image in DB but then its very difficult to do daily backups as well as restore once size grows. We tried our level best with SQL2008 to take backup without FileStream and try to restore it but we didn't succeed. And last we have changed our logic for image should show from Path.
Better to save image paths in the database and retrieve the path from db and take the image from the responsive paths.
If the you have small images then use Varbinary, otherwise use FileStream.
see this:
https://www.google.com/#q=sql%20server%20filestream%20vs%20varbinary
This is a good book will really help you:
http://download.red-gate.com/ebooks/SQL/Art_of_SS_Filestream_Sebastian_and_Aelterman.pdf
http://technet.microsoft.com/en-us/library/bb933993(v=sql.105).aspx

Categories