⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vcg20.htm

📁 Visual C++与数据库的连接经典实例
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<HTML>

<HEAD>

<TITLE>vcg20.htm </TITLE>

<LINK REL="ToC" HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/index.htm">

<LINK REL="Index" HREF="htindex.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/htindex.htm">

<LINK REL="Next" HREF="vcg21.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg21.htm">

<LINK REL="Previous" HREF="vcg19.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg19.htm"></HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">

<A NAME="I0"></A><P ALIGN=CENTER>

<A HREF="vcg19.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg19.htm" TARGET="_self"><IMG SRC="blanprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blanprev.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="Previous Page"></A>

<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/index.htm" TARGET="_self"><IMG SRC="blantoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blantoc.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="TOC"></A>

<A HREF="vcg21.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg21.htm" TARGET="_self"><IMG SRC="blannext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blannext.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="Next Page"></A>


<HR ALIGN=CENTER>

<P>

<UL>

<UL>

<UL>

<LI>

<A HREF="#E68E102" >Using Microsoft SQL Server for Windows NT 6.0</A>

<UL>

<LI>

<A HREF="#E69E251" >Networking Features and Server Performance</A>

<LI>

<A HREF="#E69E252" >Connections, Threads, and Symmetric Multiprocessing</A>

<LI>

<A HREF="#E69E253" >An Overview of SQL Server 6.0 Features</A>

<UL>

<LI>

<A HREF="#E70E115" >Using the Microsoft Enterprise Manager to Create a New Database</A>

<LI>

<A HREF="#E70E116" >Using SQL Object Manager to Add a Test Table to NorthWind</A></UL></UL>

<LI>

<A HREF="#E68E103" >Creating ODBC Datasources from Client-Server Databases</A>

<UL>

<LI>

<A HREF="#E69E254" >Adding the nwind Database as an ODBC Datasource</A>

<LI>

<A HREF="#E69E255" >Testing the ODBC Datasource with the MS Query Application</A>

<LI>

<A HREF="#E69E256" >Using Visual C++'s SQLConfigDataSource() Function</A></UL>

<LI>

<A HREF="#E68E104" >Creating Tables in ODBC Datasources</A>

<UL>

<LI>

<A HREF="#E69E257" >Exporting Tables in NorthWind.MDB to the NorthWind Database on SQL Server</A>

<LI>

<A HREF="#E69E258" >Displaying the Result of the Export Operation with SQL Object Manager</A>

<LI>

<A HREF="#E69E259" >Adding an Index to an SQL Server Table with the SQL Object Manager</A></UL>

<LI>

<A HREF="#E68E105" >Using ODBCTEST to Display the Capabilities of an ODBC Driver</A>

<LI>

<A HREF="#E68E106" >Summary</A></UL></UL></UL>

<HR ALIGN=CENTER>

<A NAME="E66E51"></A>

<H1 ALIGN=CENTER>

<CENTER>

<FONT SIZE=6 COLOR="#FF0000"><B>- 20 -</B>

<BR><B>Creating Front Ends for Client-Server Databases</B></FONT></CENTER></H1>

<BR>

<P>Up to this point, this book has used desktop database files in all the examples of Visual C++ database applications. Sample applications that use Access database files predominated in the preceding chapters because the .MDB file format is Microsoft's (and the authors') preferred database file structure for applications that don't need to maintain interoperability with existing DOS applications that share dBASE, FoxPro, or Paradox 3+ table files. Another reason for using the .MDB database file structure is that .MDB files resemble the file structures used by client-server databases.

<BR>

<P>This chapter introduces you to the principles employed to create Visual C++ database applications that serve as front ends for client-server RDBMS back ends. The RDBMS used for the majority of the examples in this chapter is Microsoft SQL Server for Windows NT 6.0 (SQL Server) running as a service of Windows NT Server 3.51 (NTS). Therefore, this chapter begins with a description of SQL Server and the use of the new SQL Administrator and SQL Object Manager database tools provided with SQL Server 6.0.

<BR>

<P>The examples in this chapter use the Microsoft ODBC API (version 2.0) and use either the MFC database classes or the SQL...() functions. The examples are equally applicable to most client-server RDBMSs for which ODBC drivers that support core-level SQL grammar and offer level-1 ODBC compliance are available. For example, a program that interacts with an Access .MDB file could easily interact with an xBase file as well. Chapter 7, &quot;Using the Open Database Connectivity API,&quot; describes Visual C++ 's interface to the ODBC API in detail and explains how to use single-tier ODBC drivers. Therefore, this chapter discusses only those elements of the ODBC API, such as creating client-server ODBC datasources, that are specific to multiple-tier ODBC drivers and Visual C++ front ends for client-server RDBMSs. This chapter includes an example of exporting data from Access databases to client-server tables because Visual C++ developers often are called on to upgrade Visual C++ (and Access) applications from desktop RDBMSs to client-server database front ends.

<BR>

<P>Designing Visual C++ front ends for client-server databases follows the same methodology as designing applications that manipulate tables of conventional desktop databases, as described in earlier chapters. If you have an RDBMS table structure that duplicates the structure of the tables that compose your desktop database, you can simply change the open statements to open tables in the ODBC datasource instead of those in the desktop database. In most cases, however, using the SQLExecDirect() function instead of the SQLExecute() method greatly improves the performance of client-server front ends when the query is a one-time execution. Thus, this chapter ends with a discussion of how to use SQL pass-through with client-server RDBMSs.

<BR>

<BR>

<A NAME="E68E102"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Using Microsoft SQL Server for Windows NT 6.0</B></FONT></CENTER></H3>

<BR>

<P>Microsoft SQL Server for Windows NT is a major upgrade from Microsoft SQL Server version 4.21. In this chapter, the term <I>SQL Server</I> refers to SQL Server for Windows NT version 6.0; references to the Sybase version for UNIX computers are preceded by the word &quot;Sybase.&quot; You can run SQL Server for Windows NT 6.0 either under Windows NT Workstation 3.5 or Windows NT Server 3.5. The SQL Server Setup program can install client software on SQL Server, MS-DOS, Windows, and Windows NT operating environments.

<BR>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE><B>NOTE</B>

<BR>

<BR>Prices and configurations of products such as SQL Server change frequently. You should think of the prices and configurations described next as a quick reference only. Before you make any decisions about these products, contact your favorite reseller.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<P>SQL Server is available in the following license versions (the prices are based on MSRP and were verified in early 1995):

<BR>

<UL>

<LI>Any number of clients may be used with the server, but each client must also be licensed (see the following note).

<BR>

<BR>

<LI>Single users (16 or fewer) are licensed at a per-user fee, typically less than $200. Microsoft defines the break point as 20 users; however, one 20-user license costs less than 16 single-user licenses.

<BR>

<BR>

<LI>A 20-user license pack costs about $2,000.

<BR>

<BR>

<LI>Licenses for more than 50 users are negotiated on a case-by-case basis.

<BR>

<BR>

<LI>SQL Workstation is a single-user version that allows up to 15 simultaneous connections. This version contains the ODBC SDK and programming files for the DB-Library. SQL Workstation is intended as a development platform.

<BR>

<BR>

</UL>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE><B>NOTE</B>

<BR>

<BR>In mid-1995, Oracle began giving away its product to anyone who wanted to pay shipping and handling or was willing to spend the time downloading the product from Oracle's Internet site for a 30-day evaluation. Only time will tell whether this approach will be successful. However, it's difficult to compete against a free product, especially when that product is as high-quality as Oracle's.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<BR>

<A NAME="E69E251"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Networking Features and Server Performance</B></FONT></CENTER></H4>

<BR>

<P>The networking features of Windows NT Server 3.5 and SQL Server are designed for maximum user convenience. For example, you can set up SQL Server so that users are automatically logged on to it when they log on to Windows NT Server 3.5. Automatic logon to the SQL Server server also is provided across remote servers in Windows NT Server 3.5 domains that share a trust relationship.

<BR>

<P>SQL Server supports simultaneous NetBEUI, IPX/SPX, and TCP/IP connections.

<BR>

<BR>

<A NAME="E69E252"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Connections, Threads, and Symmetric Multiprocessing</B></FONT></CENTER></H4>

<BR>

<P>A conversation between an application and SQL Server takes place through one or more connections established by the named-pipes service that originated in OS/2. A connection is similar in concept to that of the Windows Sockets for TCP/IP communication described in the preceding chapter. The default named-pipes protocol for communicating with SQL Server is provided by the DBNMP3.DLL library, which must be present in your \WINDOWS\SYSTEM or WINNT\SYSTEM directory or the current directory for the application. Named-pipes protocols for the other network operating systems are included on the SQL Server disks.

<BR>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE><B>NOTE</B>

<BR>

<BR>The following information relating to the Access database engine's use of SQL Server connections is based on Microsoft's &quot;Jet Database Engine ODBC Connectivity&quot; white paper, dated July 19, 1993, and written by Neil Black of Microsoft's Jet Program Management group and Stephen Hecht of the Jet Development group. You can download this white paper in Word for Windows format as RJETWP.ZIP from the ODBC Library 11 of the MSACCESS forum on CompuServe. If you use or intend to use ODBC with Visual C++ database applications, you need a copy of this white paper to understand how the Access database engine interacts with the ODBC drivers for client-server databases.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<P>When you use the Access database engine to connect to a server back end with the ODBC API and create a Dynaset object from a query, the operation usually requires at least two connections. (One connection obtains information about the query from the server, and the other passes the data to your application.) If your query is based on a complex SQL statement that involves multiple JOINs or GROUP BYs or creates a crosstab query, it's likely that your application will open several connections at once. Although the Access database engine attempts to share connections when it can, there are many situations in which your application might need several simultaneous connections.

<BR>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE><B>TIP</B>

<BR>

<BR>In a multiuser environment, it's possible to run out of connections with substantially fewer simultaneous users than you've specified as the maximum number of users for SQL Server. It's a common practice to set the number of users as low as practical to conserve memory resources, which are required for each user, for data caching. If you run out of connections, as indicated by an error message returned when your Visual C++ application attempts to run a query, your only solution is to increase the number of users. To do this, you might need to upgrade your SQL Server user license.

<BR>

<BR>With today's trend toward more and more memory in servers, the practice of limiting connection counts to conserve memory might not be meaningful. Also, in regard to licensing, SQL Server will count each workstation as a single connection regardless of how many actual connections there are between the workstation and the server.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<P>OS/2, Windows 95, and Windows NT are multithreaded operating systems. A <I>thread</I> is a single task that is executed by an application or the operating system. Multithreaded operating systems enable multiple tasks to appear to run simultaneously; the operating system determines the priority of the task and enables tasks with the highest priority to execute first and most often. Tasks with higher priorities can suspend the processing of lower-priority tasks. Operating systems that let task priorities govern tasks' flow of execution are called <I>preemptive </I><I>multitasking</I> operating systems.

<BR>

<P>Windows NT provides a thread for each connection from a worker pool of threads whose population is set by the sp_configure stored procedure of SQL Server. When a client workstation makes a request from SQL Server, one of the threads from the worker pool is assigned to the workstation's connection. When the request is fulfilled and the connection is terminated, the connection thread is returned to the pool. If a client workstation requests a thread and none is available in the pool, the first thread released by another connection is assigned to the request. When a fault occurs during the execution of a thread, only the connection associated with the thread is affected. Thus, a page fault on a single connection doesn't bring down the server.

<BR>

<P>The advantages of a multithreaded operation are particularly evident when you add more than one microprocessor unit to the server. SQL Server supports thread-level multiprocessing, usually called <I>symmetric </I><I>multiprocessing</I> (SMP), and is referred to as a <I>scalable operating system</I>. These terms mean that multiple processors that share the same memory region can execute any thread. This process is also called <I>symmetric </I><I>load balancing</I>. If a thread is executing on a processor that is running near capacity, the thread can be transferred so that it executes on another processor. Windows NT Server, and thus SQL Server, supports up to eight 80x86 processors. Multithreaded SMP operation and the capability to run on a variety of microprocessors, not just members of the Intel 80x86 series, are the two most distinguishing features of Windows NT.

<BR>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE><B>NOTE</B>

<BR>

<BR>Finding an eight-CPU computer to run Windows NT Server might be an interesting task. When this book was written, four CPUs was the practical limit.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<BR>

<A NAME="E69E253"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>An Overview of SQL Server 6.0 Features</B></FONT></CENTER></H4>

<BR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -