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

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.

Related

UnixODBC driver issues for .MDF databases. OR: is there a way to easily extract a bunch of tables without an sql server?

Disclaimer: I am somewhat of a n00b when it comes to database programming, so bear with me.
I've been attempting to batch process a rather large amount (~20 gb) of data all contained in .MDF SQL database files. The files contain meteorological data obtained through weather balloons, with each table consisting of ~1 second observations of winds, pressure, height, temps, etc, and are created with our radiosonde tracking software on an unnetworked Windows machine. It is possible (and quite easy) to load the files using the associated software and export the tables as an ASCII text file...however, this process involves manually loading each one. As I'm performing a study that requires as many soundings as possible (we have over 2000), doing this process over and over for several years of twice-daily observations is extremely time-prohibitive.
I've been taking the files off of the computer and putting them on my laptop running Linux Mint, and consider myself to be fluent with Perl...I do most of my data analysis with Perl scripts. That said, I've had the darndest time trying to get into the database files!
I've tried to connect to one of the files using the DBI package using variants on
$dbh = DBI->connect("DBI:ODBC:$filename") or die "blahblahblah";
I have unixODBC installed and configured, have downloaded "libmyodbc.so" and "libodbcmyS.so", and keep getting the error
DBI connect('','',...) failed: [unixODBC][Driver Manager]Data source name not found, and no default driver specified (SQL-IM002) at dumpsql.pl line 6.
I've tried remedying this a number of ways over the past couple days, and I won't post them here for the sake of brevity. My odbcinst.ini file is as follows:
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
Setup = /usr/sib/x86_64-linux-gnu/odbc/libodbcmyS.so
FileUsage = 1
I'm seriously confused. I THINK I'm doing everything that various online tutorials are suggesting, but everyone else is connecting to servers and these files are all local and in the same directory! Could anyone attempt to point me in the right direction? All I want is to calculate meteorological values using vertical sounding data! Am I missing something totally obvious?
Any help would be greatly appreciated!
It seems the original database server was a Microsoft SQL Server (MDF files). I am afraid these files alone are useless on a Linux machine. You need a Microsoft SQL Server on a Windows machine to get access to the contained data.
You described that you are able to attach a MDF file on a SQL server manually and then you can export the needed data as text files. Try to automate that. I'm not a MS SQL Server expert but it should be possible.
E.g. here is a tutorial to attach and detach a MDF file via T-SQL. So my approach would be to write a script which iterates over the 2000 MDF files and attach each to the SQL server. Then execute a query to export your data and then detach the MDF.

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.

Creating a local SQL database file?

Please note:
I am a game programmer, so backend development isn't my forte. There are times, however, where I work with our database at my job. Please don't shoot me if my question is ridiculous.
Is there a way to create a local mySQL file and access it through PHP or C#?
I know you can make a local webpage on your machine (pretty much for testing purposes) and access multiple locally created files.
I assume that something similar would work with mySQL. (Are the login credentials also stored within the file?) I remember seeing a few online tutorials where it offered a download for both PHP and the database file, but I can't seem to find them now.
I've searched for this, but all the relevant results involved downloading mySQL and hosting a server which is a bit more than I wanted to do.
So if its possible to create a local mySQL, how do you do so?
The tools I intend on using while doing this:
PHP/JQUERY/HTML and C#
For MyISAM tables, inside the MySQL data directory there is one directory per database which contains several (usually three) files per table. For InnoDB tables, they are all contained in several files directly inside the data directory.
The location of the MySQL data directory is usually set in my.cnf using the datadir parameter.
The login credentials are stored in a special database called "mysql" which is in that data directory like any other database.
However, you have to install and run MySQL to access those files. You cannot access them with PHP or any other client API alone. If you want to do such a thing, better use SQLite.
MySQL is a database engine, u need to install that before you can use it. Unlike SQLite which stores it's database in files. Maybe that is something more of your liking. And I know there are library that supports SQLite for PHP, not sure about the rest.
SQLite you don't need to install anything.
MySQL can be used an an embedded database, but you will need to contact them in order to purchase a copy of it.

How to edit a Word Document (.docx) stored in a SQL Server Table?

How to edit a Word Document (.docx) stored in a SQL Server Table?
Here is the tentative work flow:
Read BLOB from SQL Table through Ideablade
Write BLOB to disk as .docx
Open .docx using Word
User makes changes
Save .docx using Word
Read .docx into BLOB
Write BLOB back to SQL Table through Ideablade
All sample code is welcomed?
I am sure there are a lot of people doing this already.
Any other ideas on how to simplify this process?
I am using VB.NET, .NET 3.5 SP1, WinForm and SQL Server 2008.
Well, as to the how, here is how to read a blob and write a blob to SQL. Although frankly, unless you have very good reasons such as an existing backup system, you would probably be best served storing the file to the file system and the path and metadata in the database. Either way, abstract it in your BLL, so you can change your mind down the road.
Retrieving and updating the BLOB from the db shouldn't be a problem, you'll find lots of sample code to do that on the net.
A simple approach to your problem would be to create a "temp" or "working" directory somewhere and monitor it with System.IO.FileSystemWatcher (sample code). When the user wants to edit a file, fetch it from the db and store it the directory. Whenever the user saves the file, you'll get a notification from your FileSystemWatcher, so you can save it to the database. Don't forget to empty the directory from time to time.
The method I've seen for this that I think works best is to build this as an add-on for MS Word itself. Examples include the Save to Sharepoint, Save to Moodle, and other similar add-ins.

Questions about Sql Server 2008 FullText Search

I'm using Sql Server 2008 FullText Search for a project. I need to be able to search PDf files, and I had some questions relating to that:
How do I enable PDF searching? I've heard of the adobe filter, but couldn't find a clear guide on how to get started.
Are the PDF files stored in the DB itself, or in the file system? I was mainly concerned about the space on shared hosting services like DiscountASP. Typically, we get only about 100MB of space for the DB, but a lot more (in GBs) for the File System.
So, if these PDF files are going to be stored directly in the DB, then it may get expensive, right?
I would like to provide snippets of the search results (like Google). How can I achieve this with Sql Server 2008 FTS?
Full text search can only search database content. It will not index content outside the database. Fulltext is extensible through a programming API and Adobe has providers for PDF content, as you already know. SQL Fulltext can use those providers.
However there is another feature you may be interested in, namely the new SQL 2008 FILESTREAM data type. Filestreams are stored in the file system as files but are maintained as part of the database from the point of view of transaction consitency, backup and restore etc. Luckly FILESTREAM and FULL TEXT work together.
Sounds like you want to use Microsoft Indexing Services
This will index files on the file system so you can search their contents.
Here is an example of querying indexing services using ASP.NET
You need a PDF IFilter. Here's the one from Foxit Software.
I believe you can only use 'Sql Server Full Text Search" if the PDF files are stored within the database.
I haven't found a way to do this other than opening the file and searching for the context myself for each result.