Get image from SQL Server to show it in ASP.NET application
I want to get an image from SQL Server in order to show it in ASP.NET application. I think I can write the image I got from SQL Server to the server folder and show that it throws its path. Is there any other better way?
I have the same problem with audio and video files (can I use Silverlight to play these audio and video files?)
My concern is that I do not want to store these files (images, audio and video) on the server in order to display it.
a source to share
You can write your own HTTP handler that accepts the ID of the element you are trying to display in a query string parameter.
This handler will then fetch data from SQL Server and return it in the same way as a file download. This post has the following steps.
I'm not sure about the Silverlight streaming capability from a "file", you might need to use the Silverlight Streaming Service .
a source to share
Is there a better way? IMHO, yes there is. Store the image file as a file. This is what the filesystem is for, and you are not involved with the database.
I have used MySQL in the past to store images and retrieve them with PHP, but this solution really became very fast very quickly in terms of maintenance. It boils down to the fact that you always need to store data in some way, and the most efficient way is also the simplest.
If you must store it in a database, I would use a generic access page (like myImage.aspx) that queries the database and passes the returned control back to the browser. Your img tag should probably then look like
<img src="/img/myImage.aspx?imgId=123456" <other tag data> />
a source to share
HI everything, I think the solution for this is present in the links below:
http://www.codeproject.com/KB/aspnet/asp_net_and_mysql.aspx
http://www.codeproject.com/KB/aspnet/image_asp.aspx
This solution is for mysql database and can also be modified accordingly to work with mssql database.
a source to share