Use SQL Server to provide image 1 for your web browser

Source: Internet
Author: User
Tags log microsoft sql server one table table name
Microsoft SQL Server database server can save pictures and a lot of text in SQL database. The data types used for pictures and text are image images, respectively.
piece type and text text type. If you use VB or VC to develop front-end applications, running on the Windows operating system, then you can easily from the SQL database
Extract the image data, put it into a file, and display it on the screen. However, if you want to get a picture from SQL Server and display it in a Web browser,
It's not that easy. Although web assistants and stored procedures sp_makewebtask and sp_runwebtask are available in Microsoft SQL Server 6.5, they can
The data in the SQL database is converted into HTML files, but we have a better solution. One problem with Web assistants is that it does not accept the image data type
Field. Stored procedures, on the other hand, sp_makewebtask too many parameters, are difficult to use, and are difficult to customize for Web pages.

We have a solution here that loads images from SQL data into a Web browser, which is better than sp_makewebtask. We use a
An ActiveX dynamic-link library and ASP page developed a Web project. The dynamic link Library is responsible for opening the connection to the SQL database where the picture is saved, extracting the graph from the database
And keep them in a temporary file. The ASP communicates with the dynamic link library to obtain the location of the temporary picture file. This way, when a visitor clicks on a Web site,
The picture will be downloaded to his browser. In this article, we want to introduce the steps for setting up a SQL database. Then, we'll also explain how to use VB5 and activities
Data Object ADO 1.5 establishes an ActiveX dynamic link library. Finally, we'll discuss building ASP Web projects, connecting to SQL databases, and writing ASP files.
Process.

Set up SQL database

The database used in this article is very simple and contains only one table, named Products, representing a variety of different items in a small grocery store. Set up
The first step in the database is to build a database device in Microsoft SQL Server (Translator Note: In SQL Server 7.0, the concept of a database device has been taken
Elimination). Although you can write SQL scripts to set up a database, it is easier to use SQL Enterprise Manager operations. Open Enterprise Manager, select the database in the tree
Device (Database Device). Click the right mouse button and select New Device in the shortcut menu. In the Name field, enter
Grocevb_dev, set the size of this device to 2MB. Then, by clicking the Create Now button, the database is established. Then, with the same
method to establish another database device as a log file. Give the device a name of Grocevb_log, and set its size to 1MB.

Next, you need to create a new database. Select the database in the tree and right-click. Then, select the new database in the pop-up menu
(New Database). In the Create a new Database dialog box, enter the database name Grocevb, and from the Drop-down list to select the previously established Grocevb_dev
As a data device, Grocevb_log as a log device. Then, click the Create Now button and the database is set up. We temporarily ignore the
Database security, database backup, user access, and so on, because they are not directly related to this article.

The database we created has only one table, the table name is products. There are several fields in this table, of which there are two fields Prod_image and
Prod_imagetype need special instructions. The data type of the Prod_image field is an image image, where a picture of a product is saved.
The Prod_imagetype field holds the type of picture, such as. gif or. jpg, which is the two most commonly used picture types on the Internet. The primary keyword for this table is
PROD_ID, which is an index of a nonclustered cluster. In this way, each picture has a unique prod_id. In List A, we give the SQL foot to create the Products table.
This. In this table, there are only four products for this demo.

List A: Create a script for the Products table.

/** is used to establish imageloader VB Dynamic link library using the Product table. **/
CREATE TABLE Products
(
prod_id int CONSTRAINT pk_prod PRIMARY KEY nonclustered IDENTITY (1, 1),
categ_id int NULL CONSTRAINT fk_prod REFERENCES categories (categ_id),
Prod_name char () not NULL UNIQUE nonclustered,
Prod_unitprice money is not NULL,
Prod_unitquant char (not NULL),
Prod_desc varchar (255) NULL DEFAULT (' unknown '),
Prod_imagetype char (3) not NULL,
Prod_image image not NULL,)
Go


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.