Extract Binary Data from SQL Server using T-SQL - sql-server

I have a database to which I upload files (such as PDFs, images, etc). I save these to the database as Varbinary (max).
I upload these files using C# MVC. What I was wondering is how can I view these files using a T-SQL query, not .net.
Is this possible?

Not directly.
Why don't you write a simple viewer application?
There are free and commercial ones out there. I haven't used this one, but it does have a trial version: SQL Image Viewer

No, you need to extract the files in order to view them.
SQL Server and SSMS (SQL Server Management Studio) don't have a facility to view binary data in this way.

You can use the sp_OAxxxx functions (the COM interaction functions) to create the appropriate viewers, but ultimately these viewer will require the data written to disk.

Related

Relational database tool, which can display PDF blobs

I would like to collect my orders in a very simple relational database with some PDFs inside binary a field. I would like to easily browse the PDFs without building a frontend. There are many SQL admin tools available which are perfect for browsing the databases, but I have not found any free tools which could display the PDFs inside it or open them easily.
Which existing free and platform independent tool is able to show PDFs in a database?
For example:
SqlLite Studio has a "Edit value" window, which can display the stored image.
SQLMastro is able to do it, but is not free.
Images can also be shown in LibreOffice Base and Microsoft Access.
In MS Access VBA it is possible to embed ActiveX applications or open a PDF stored at a path, but MS is not platform independent and VBA is very messy.
I would also be happy, if it would actually store a copy of the file temporary on the harddrive and automatically open it. I just want a single click solution.
I did not specify the actual database format, as I am happy to use any relation database which has such a tool already. I want to use some database instead of a magical folder structure.

How to convert .gdb database to SQL Server

I have a .GDB database (old one) and the data in it is very important
I need to convert that .gdb database to a SQL Server database - can anyone help me...
Create connections to both source GDB and Destination SQL Server in ArcCatalog. Copy everything from source and paste it into the destination. You won't be able to do it with SQL tools alone.
Lacking ESRI software, for simple cases, my workflow is to use the GDAL C++ API to read the GDB. This requires the GDAL File GDB driver. Then I will use Microsoft.SqlServer.Types to transfer to SQL Server. This involves low-level APIs and you need to understand the spatial types in the respective libraries. It gets complex if you have polygons with rings, for example.
I'm not aware of a tool that will automatically convert between these database types. You'll need to use an application that can read the old database type (Firebase), learn the table design, create a similar table design in SQL Server, and use the application to load the data from Firebase to SQL Server.
Typically, this kind of work is called ETL (Extract/Transform/Load) and is done with migration tools like SQL Server Integration Service (SSIS). SSIS is free with SQL Server, and there are a lot of books available on how to use it - but like learning to develop software, this isn't a small task.
The easiest way to export Esri File Geodatabase FGDB (.gdb) data to MS SQL Server is with ArcGIS for Desktop at the Standard or Advanced level.
You may also want to try exporting to shapefile (SHP) format (an open transitional format) then import to your MS SQL Server. I've seen a tool online that has worked for me called Shape2SQL.
Esri also has an open File Geodatabase API that you can use to write your own too.
I highly recommend FME Workbench for GIS data conversion. It's like SQL Server Integration Services (ETL) but for GIS. Graphical interface, connect data readers with data writes, insert transforms, run them, etc.

What datatype should I use for saving a file in a SQL Azure database?

In this case it will be potentially large PDF files. I will be using Entity Framework to insert and retrieve the files. Before anyone mentions it, I am aware that many believe that I should only save the path to the file in the database. I am not interested in doing it that way in this instance. :-)
Although SQL Azure supports these datatypes: binary, varbinary, image,
Blob storage might be a better (and cheaper) option:
Storing binary data (images, files, etc) using WPF + Windows Azure

How do I store pictures in SQL Server (MS Access interface)

Following podcast #59, I've been considering moving some images from an MS Access DB into MS SQL Server (it's the only piece I haven't migrate over yet). Right now they are stored as OLE Objects in the MS Access DB.
However, I haven't got a clue what data type they should be stored as on the SQL Server side, or how to get them inserted through the interface (MS Access via ODBC).
I would use the image type, and I would NOT use Access to transfer them. I'd use the Sql Server Import and Export Wizard to do it. To do so, right-click the database you want to import to in Sql Server Management Studio, select Tasks, and then select Import Data.
There is several BLOB-type fields in MS SQL Server for storing binary data - but some of them have size limitations.
If you use SQL 2005 or higher, the best choice is varbinary(MAX). It can store really big data pieces.
Be warned, that keeping pictures in OLE format will cause a lot of problems for you in future. While you're moving on, consider converting your images to usual graphic files (like JPG). It will save resourses of SQL Server and improve Access displaying speed.
I recommend to take a look at AccessImagine (http://access.bukrek.net), it would help you to avoid a lot of headaches about the images. Just look at video.
We have used DBPix from Ammara, www.Ammara.com for 5 or 6 years now to handle the capture and display. Very easy to use ActiveX control with complete sample code in their documentation, and affordable.
Our team preferentially stores images on disk and refers to them by storing their location in a varchar, but the control will handle both methods.
You can try to compare em, it can be interesting as AccessImagine is newer one.

Can I integrate SourceSafe / VSS with SQL Server 2005?

How are the SQL objects managed with VSS?
Can I integrate SourceSafe / VSS with SQL Server 2005?
I want versioning in my SQL schemas.
Aside from VSS being a total train wreck, if you want to store your schema in source control, one possible approach is to store the object creation script for each database object as a separate file in source control. That way, you can update individual parts of the schema easily. So you have a script for each table, trigger, index, procedure etc. As part of your build process these can be pulled together into a single script for ease of application to the target database.
Utilize tools like SQL Compare from Red Gate which will allow you to create schema, object per file, and then maintain the state of the files with VSS. I am currently trying to push that in my organization.
We've just added Visual Source Safe support to SQL Source Control, providing source control integrated into SQL Server Management Studio. This is in early access at the moment so please sign up for the early access build and tell us what you think.
More detail is available here:
http://www.red-gate.com/MessageBoard/viewtopic.php?t=12265

Resources