Home > Archive > SQL server exams > April 2002 > Insert Question. URGENT





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Insert Question. URGENT
mauro

2002-04-17, 12:20 pm

URGENT !!!

I need to insert a "MS Word File" in a SQL Database field.

An Example:

Table
-----
Name Char 50
Adress Varchar(200)
WordFile Binary (I guess).

In this row (Wordfile) i would like to put a MS Word File, and read it ?

Someone have an example or some reference ???

Thanks





felafel

2002-04-17, 3:28 pm

Why would you want to put a file in a database? Why not just put the name or path and then use a program (Word?) to open it?
J-Ho

2002-04-17, 3:49 pm

quote:
Originally posted by mauro

WordFile Binary (I guess).



Don't use binary. From BOL:
A column assigned the binary data type must have the same fixed length (up to 8 KB) for each row. In a column assigned the varbinary data type, entries can vary in the number of hexadecimal digits (up to 8 KB) they contain. Columns of image data can be used to store variable-length binary data exceeding 8 KB, such as Microsoft Word documents, Microsoft Excel spreadsheets, and images that include bitmaps, Graphics Interchange Format (GIF), and Joint Photographic Experts Group (JPEG) files.

In other words, use Image instead.

quote:

Someone have an example or some reference ???


Sure, BOL and MSDN has plenty.

If you're using ADO 2.x, use the AppendChunk and GetChunk methods. There are samples in MSDN.

Dunno how you do this in ADO.NET, cause I've never had to learn it yet:-) I'm sure that's in MSDN as well tho.


Let me know if you need further help,
J
J-Ho

2002-04-17, 3:50 pm

quote:
Originally posted by felafel
Why would you want to put a file in a database? Why not just put the name or path and then use a program (Word?) to open it?


I can think of plenty of reasons; e.g. a document collaboration system online; managing what/how data is published on your company website; a source code management system like Visual Source Safe etc.

You're right to ask tho; "Why" is often more interesting than "How"...
mauro

2002-04-18, 5:48 am

Its looks like a great ideia, but in fact the files don't must to be see for other peoples, just the owner of this file.

Image a directory with 1000 files and one file below to me, so i get my file and can see another 999. Isn't a good ideia.

Thanks

quote:
Originally posted by felafel
Why would you want to put a file in a database? Why not just put the name or path and then use a program (Word?) to open it?
mauro

2002-04-18, 5:53 am

Thanks 2.
But i dont like to share the files, its looks like simple storage a file in a database (So its looks like), but i cant find any example.

quote:
Originally posted by J-Ho


I can think of plenty of reasons; e.g. a document collaboration system online; managing what/how data is published on your company website; a source code management system like Visual Source Safe etc.

You're right to ask tho; "Why" is often more interesting than "How"...

mauro

2002-04-18, 6:05 am

Can you show me an example please. Anyone
quote:
Originally posted by J-Ho


Don't use binary. From BOL:
A column assigned the binary data type must have the same fixed length (up to 8 KB) for each row. In a column assigned the varbinary data type, entries can vary in the number of hexadecimal digits (up to 8 KB) they contain. Columns of image data can be used to store variable-length binary data exceeding 8 KB, such as Microsoft Word documents, Microsoft Excel spreadsheets, and images that include bitmaps, Graphics Interchange Format (GIF), and Joint Photographic Experts Group (JPEG) files.

In other words, use Image instead.


Sure, BOL and MSDN has plenty.

If you're using ADO 2.x, use the AppendChunk and GetChunk methods. There are samples in MSDN.

Dunno how you do this in ADO.NET, cause I've never had to learn it yet:-) I'm sure that's in MSDN as well tho.


Let me know if you need further help,
J

J-Ho

2002-04-18, 11:56 am

quote:
Originally posted by mauro
...the files don't must to be see for other peoples, just the owner of this file.

Image a directory with 1000 files and one file below to me, so i get my file and can see another 999. Isn't a good ideia.
...



Is this your main goal, enforce permissions on files? If so, you'd be better of using NTFS permissions and/or Encryption File System in Windows 2000+.

Also, you should seriously question putting 1000 files together like that. It can turn into a maintenance nightmare.

If you're dealing with fairly few users contributing files, it might be a better idea to give each users their own directory (or create directories based on project, month the documents are created, department or whatever makes sense), create a DFS that abstracts the actual directory structure and assign proper permissions.
J-Ho

2002-04-18, 11:57 am

quote:
Originally posted by mauro
Can you show me an example please. Anyone



Can you explain the intended architecture? Are you creating a dedicated front end; is this a Win32 app or a web page; what languages and technologies are you using besides SQL Server?

The more info you can give, the better.
mauro

2002-04-18, 1:10 pm

Windows 2000 Server and ASP (Active Server Pages) and would like to choose a file and put in my SQL Server 2000.

Regards

quote:
Originally posted by J-Ho


Can you explain the intended architecture? Are you creating a dedicated front end; is this a Win32 app or a web page; what languages and technologies are you using besides SQL Server?

The more info you can give, the better.

J-Ho

2002-04-18, 3:40 pm

Cool.

VBScript or JScript? Or maybe PerlScript? :-)

I assume you're using ADO 2.x, not ADO.NET.

So you need a function that takes a byte array and adds to SQL, using ADO.

In short, what you do is
1) read the contents from the binary file into a Variant or Byte array
2) open a connection
3) open a recordset on the table
4) add a record
5) creates a loop that will AppendCunk() x entries from the Variant or Byte array or so to a field in the new record, until all entires in the array have been added.

MSDN has a pretty good example on using AppendChunk (and GetChunk for reading the data back again), but for copyright reasons I won't repeat it here.

You can find it at "Platform SDK\Data Services\MDAC SDK\ADO\ADO Methods\AppendChunk" in the tree view in MSDN.

It's kinda straight forward, once you've looked at the sample.
Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2008 examnotes.net