Answer the question
In order to leave comments, you need to log in
Convert BLOB image from bmp to jpeg in MS SQL DB
Hello.
Problem in the following, the client (.NET, Entity framework) allows to save pictures in a DB (MS SQL).
After some time, the database began to swell due to bmp images and decided to automatically convert them to jpeg when saving, everything is simple here.
But it would be nice to convert already saved pictures to the database.
The question is how to do it without complicated body movements.
The architecture of using the Entity framework allows you to write upgrade scripts in the code that run when the application starts.
Where on good also it is necessary to make this conversion.
Example:
public class MyUpgradeScript: DbMigration
{
// запускаем нужное преобразование с БД
public void Up()
{
}
public void Down()
{
}
}
Solutions:
1) Use standard MS SQL tools/scripts, they can simply be run using the Sql("select * from db") method. But I did not find such means and it seems to me that they do not exist ....
2) Run Power Shell from the Up method and use it to make transformations. This option seems like a “new bike” to me ...
3) Somehow directly access the database through Context or through ADO.NET and do the necessary manipulations.
Here I think in what direction to dig.
What can you advise on this issue?
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
Brrrr… And what does the “SELECT * FROM Table” method return????
You just need to work with blobs through streams
msdn.microsoft.com/en-US/library/3517w44b (v=vs.80).aspx?cs-save-lang=1&cs-lang=vb
Why complicate it?
The operation is one time. For old pictures.
Write a simple program that will select everything you need from the database, convert it and write it back.
unconnected , I don’t want to complicate it, you just write about my option 3. Only in my version this program will be launched in the migration test. It’s just that I don’t have much experience with EF and I still don’t know how to do it accurately.
It is a pity that the Sql("select * from db") method does not return data, then the task would be solved simply. I pulled out the info, converted it using .NET and then updated it using Sql ("update").
sebres , 2 uses third-party utilities, 3 uses .net code. To be honest, your option in 1 seems complicated to me too. Although maybe I'm not a SQL guru.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question