MS Access, SQL Server image field - c#

I have spent nearly 2 days in trying to figure this out. We have an Access Project (adp) from Year 2000 that stores images to SQL Server 2008. I have tried connecting directly to SQL Server and to open TIFF files but it didn't work. Also tried to copy/paste the image field content into a file, renaming as TIFF and trying to open it but it didn't work as well. The problem with the content in the image field is that it is not of the right size. It is only 15-20KB but the files at that point should be around 3MB. It works fine if I retrieve the same data back in to the ACCESS project application.
I have tried TiffLib.net and few other things.
So, has anyone got any idea on how to migrate those image fields into SQL?
Thanks

Well the Image data type stores a binary version of your image.
Now the conversion process is explain in the below links.
You'll need to use a library to convert a byte array into image object.
http://www.akadia.com/services/dotnet_load_blob.html
http://www.dreamincode.net/forums/topic/103960-save-and-retrieve-images-with-sql-server/
Hopefully this helps.

Related

Blazor pdf File Read/View from SQL Server

I am currently building an application using Blazor with a SQl database. The application allows for a user to upload pdf files to the server.
I've been searching for a simple and efficient way to read/view the pdf files from the SQL server but can not seem to find anything relevant.
I would prefer not to use JavaScript like in : https://www.pdftron.com/blog/webviewer/add-webviewer-to-blazor/
Anyone got a solution to this? Any help or tips would be greatly appreciated.
You could get the pdf as a byte array and render that in iframe.
Here is a similar question
just the source of data is different. If you store the data as a BLOB in the SQL server you should able to grab the data and convert it to base64.

What's is th best way to manage pictures WP 8.1

Actually I'm developing an "social" app for my office and I'm wondering what's the best way to load or manage pictures. Each user has a profil picture and I would like to display it wherever I want, on the profil view, in the contacts list (little smaller) for example. When the user creates its profil, he picks up a picture from the picture library on his phone and it's send to server as base64 encoded string. The code that I've used to save the picked picture on the server (SQL Server 2012 database):
var reader = new DataReader(pictureStream.GetInputStreamAt(0));
byte[] bytes = new byte[pictureStream.Size];
await reader.LoadAsync((uint)pictureStream.Size);
reader.ReadBytes(bytes);
string bytesString = Convert.ToBase64String(bytes);
So here bytesString contains the base64 encoded picture to send on the server. Atually, I'm facing two problems.
First problem:
The base64 encoded string cannot be inserted to the database even if the column type is varchar(max). The string is cut in the table.
Second problem:
If I want to build the picture from bytesString decoding the base64 string, it takes so much time that it's not possible to work like that.
So I'm wondering how applications such Instagram or other picture specialized application are managing pictures so well... Does anyone could give me some advises to manage pictures through an app ? Thanks in advance !
Two ideas come to mind:
1. Store the images in a binary-type column
I haven't used SQL server very much, but I guess there is a binary column type in which you can just store the original bytes of the image.
2. Store the images in files instead of the database.
Another thing you can do is to simply store the images in files with names based on the users' IDs (i.e. user_15.png).
Other considerations
Is there any reason to encode/decode the bytes? Sending the original image seems like a better option to me.
How are you actually sending the encoded image bytes? From what I understand varchar(max) should be able to hold quite a lot of data. Are you sure the server receives the right data?
On the client (in the WP 8.1 app) you may want to cache the images, so that you wouldn't need to load them from the server every time.

Webclient image upload to server

This is a follow on from my last question (Here) as I don't think I gave enough information the first time around and i can't delete it.
I've got my image converted to a byte array but the follow on help and suggestions made it seem like that the image I wanted to save needed to first exist on my computer. Where, in fact, the image I want to take only exists in the picture box (its a screen grab). When I check my server to see if the image has been passed over, I don't see anything and nothing prompts me to name my image file or anything.
So my question is thus:
What is the best way for my to upload a screen grab from my application, using webclient, to my central server? Ideally the functionality I would like would be very similar to that of saving the image to my computer. The only difference is, it's not my hard drive I'm saving the image on. It's a server somewhere.

Storing references to images in SQL Server using ASP.NET and C#

I am trying to store references of images in a SQL Server DB and store the actual images in a file server/folder. I am hoping someone could give me a link or code example on how to do this. I don't want to store BLOB in the database.
I am using ASP.NET/C# to handle this.
All files in a folder have unique names, so I think you shouldn't worry about storing the path of the image, as suggested in the comments. If you are worried about consistence, i.e. someone deleting a "referenced" image or inserting a path to nonexistent image file, you could check that either from your application, or even from the database itself.
However I would not hesitate to use a blob, you can use MS SQL 2012 and insert the image files to a file table, which sounds quite convenient.
as per my knowledge.or my expirence the images are stored in sql server that is in image datatype feild.it is stored in byte format.that is actlly the reference of the actual image.hope this link help you to get more clear idea about it
http://www.sqlhub.com/2009/03/image-store-in-sql-server-2005-database.html
http://www.codeproject.com/Articles/10861/Storing-and-Retrieving-Images-from-SQL-Server-usin
Use a HttpHandler to grab the image from the database and use the Image data type:
Retrieve image of image control as byte array which is set using generichandler(.ashx)?
Storing images in your dataase or in a filestream, totaly depends on your images size. In Microsoft Research there is a good paper called To BLOB or Not To BLOB.
After a lot of test and much analysis;
If your pictures are below 256K, store them in datebase VARBINARY column is good.
If your pictures are over 1 MB, storing them in the filesystem is good.(With FILESTREAM attribute, they are still under transactional control and part of the your database)

getting binary format for displaying image in datagridview

i am currently facing some problem retrieving image for display on a datagridview control.
The Image data type in the database is blob.
I am using mysql as a database for retrieving the image . may i ask if it is possible to just retrieve a image data of this format and display in the gridview? or do i need to store the image in a image folder for retrieval?
I am using winforms application
Don't really think it's possible to figure out EXACT format of the image from its binary stream. The only solution I met, is storing the format in DB too, or have architectual convension to store in DB only one format type images.
Storing it in the local folder shall help you if you wish to reload it again later provided the DB isnt modified. Other wise i dont see any benefits here. Some times DB access is faster.

Categories