I need to generate a file from binary information in sql - sql

I am writing a windows desktop application in visual basic and I need it to connect to a SQL database, take a rows unique id, and using that number generate a file from the binary data that is stored in the SQL database and save it to a file directory.
The part that is hanging me up is the creating the file from the binary SQL data.
Any help would be appreciated. Thanks.

Here is an example which shows how to store/generate images from sql server database: How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET You can use it for any type of file.

VB6 or .net? You have both tags but the text says only visual basic.
Possible solution:
http://www.vbdotnetheaven.com/UploadFile/mahesh/BLOBinAdoDotNet04232005065613AM/BLOBinAdoDotNet.aspx

Related

Store PDF or image in SQL Server database with navicat or sql management studio

This one's going back to the basics but I haven't been able to find a simple explanation anywhere. I just started working with databases and I'm using a SQL Server database managed mostly with navicat (but I have SQL Server Management Studio as well) and I need to store a PDF or image in the database.
I'm using Entity Framework to interface the database with the C# app I am building. A simple explanation assuming little knowledge of database management would be much appreciated.
Thanks for the help.
The database size will grow exponentially if you start storing images and PDF's.
A better approach would probably be to store the path of the file in the database and then load the item by referencing the proper path.
EDIT:
It's going to depend on the file structure of your application really. A simple version of retrieving a PDF could be the following:
Example Path:
/PDF/username.PDF
You store the path of the PDF in the DB, maybe under pdfPath. Then when you retrieve the path from the database direct the user to the correct link using the path you got from the query.

How do I upload an Excel sheet to a SQL table in a Lightswitch web client?

I have a lightswitch project in visual studio 2013, using vb.net. I would like the user to be able to click a button and have lightswitch find an excel file, and upload that file to a sql table according to a pre-determined column mapping.
My preference was to use the Office Integration extension for visual studio, which I got working with VS 2013 by downloading it from this link: http://www.ge.tt/71iuRQv/v/0
However, the documentation and examples for office integration seem to be very heavy on getting an excel spreadsheet into a display in the lightswitch web client, rather than into the sql data table, which is where I need it. Here are the examples I've been following:
http://blogs.msdn.com/b/bethmassi/archive/2012/07/18/new-and-improved-office-integration-pack-extension-for-lightswitch.aspx
Alternatively, I have an existing stored procedure, and I can request that the server call this stored proc by sending a web API extension from the client to the server. I have this working already for other stored procs, according to examples from Beth Masi and Paul van Bladel. (Stackoverflow won't let me post the links...)
The undesirable part of this approach is that the stored proc is old, and messy.
I've searched and searched, but have yet to find anyone approach this problem for VS 2013 with lightswitch. Any useful advice?
I've used the method detailed by Matt Sampson to store word files and it works very well. Since it just stores the raw binary it should handle Excel files just as well.
If you're creating the table in LightSwitch, use the Binary Type. If you use SQL create scripts use varbinary(MAX).
You need to create a custom Silverlight dialog box to gain access to the OpenFileDialog object. Then open the file in as a FileStream.
Finally, you need to add a handler for the closed method of the control and then show the control to the user. Most likely done in a button. This needs to be done on the main dispatcher.
The code examples are in C# but I just used one of the many available translators out on the web and copy/pasted the VB.NET code.
Another option might be to consider shelling out to the DTSEXEC run-time to execute an SSIS package to perform the upload - especially if the target Excel spreadsheets have predefined layouts and content data types.
Even simpler, you might be able to use the SQL Server BULK INSERT command to get the job done - although that would require a SQL Client connection to your database.
HTH

Saving an Access table as dBASE_IV file (.dbf) in VB.NET

I am making a small application that will read .csv files into a newly generated access table (generated with vb.net), I am filling this database with sql and now I would like to output that table as a .dbf file!
I can't find any info on this subject.
I know some of you will tell me to just make the script in vba in access, but there are some functions that require me to use vb.net and the client wants a single .exe file.
There is a forum post here that includes some VB.NET sample code to create a .dbf file and write some data into it. The code uses the Visual FoxPro OLEDB driver (VFPOLEDB) which is no longer distributed with Windows by default, but can be downloaded here.

Visual Basic data file location

I would like to know if there is a place to save a file that contains some data (that is used internally by the application - like a very tiny db). I don't want to save it to C:\file.txt. Is there a place where visual basic can hold these kind of files, like bin or something?
Thank you.
You can use the path in the VB object My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData or My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData to store what you want.
It is not clear what kind of data you are talking about (type, size and usage), but an embedded database may be just what you are looking for.
SQL Server Compact Edition or SQLite may do the trick.
You have a few choices.
You can store data in Arrays, XML files, A SQL Database (Access, SQL Server, etc).
You can use your local user locations that are user specific.
IT all depends on how much data.

How Do You Save An Image Out of a SQL Database Into the File System Using only SQL?

Similar to this question only the other way of flow.
Insert Picture into SQL Server 2005 Image Field using only SQL
I need to be able to save a image field out into the file system and be able to name the file with only using SQL. I don't want to use TEXTCOPY either because I need to use the connection to the database that is running the query itself.
I'd like this to work in SQL 2005 to support older database clients but if it's available in only 2008 that's fine.
Any ideas?
With SQL 2k8 there is the new FILESTREAM type that covers such cases. Filestreams can be opened via the Win32 file access handle like any other file, but hey are integrated into the database from transaction and backup/restore point of view.
I had a similar issue in SQL 2k5 and my solution was to use a CLR stored procedure with EXTERNAL_ACCESS that was writing into the file system using C# file operations.
I don't believe there is a way to save out using only sql, but there is a command-line utility, bcp.