DBViewer Sample: Database Browser
The DBViewer sample is an enhancement of the MFC DAOVIEW sample. It demonstrates a mid-level application that relies on the OLE DB Templates CManualAccessor class. This sample illustrates how to take full control of the bindings and use them for your applications.
Security Note |
---|
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties. |
To get samples and instructions for installing them:
To access samples from Visual Studio
On the Help menu, click Samples.
By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.
- For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.
Building and Running the Sample
You can use DBViewer with the ODBC provider, and with Microsoft Access databases and Microsoft SQL Server 6.5 databases. However, DBViewer cannot handle SQL Server stored procedures that have integer parameters, or that have names that have more than one word, for example, My stored procedure. You will get errors in these cases.
To build and run this sample
Open DBViewer.sln.
On the Build menu, click Build.
On the Debug menu, click Start Without Debugging.
A DBViewer dialog box is displayed, and has two panes.
On the File menu, click Open to display the Data Link Properties dialog box. On the Provider tab, select Microsoft OLE DB Provider for SQL Server (or Microsoft Jet 4.0 OLE DB Provider). On the Connection tab, select a database such as Northwind.
After you have connected to a data source, you can manipulate the data, call the stored procedures, and view the schema information. The tree view in the left pane displays the tables and the stored procedures in the specified database. To view or modify data, right-click a table or a stored procedure, and then click the command you want.
Remarks
Not all stored procedures will run under this sample because the underlying ODBC drivers do not provide support for some OLE DB methods. DBViewer does support multiple-result sets. If you click the list view where the data is located, you may see the multiple result sets button highlighted on the toolbar. You can click it and obtain the next result set.
DBViewer demonstrates how to use the error information in your application. The CErrorsDialog class handles the IErrorRecords interface and displays the error information returned from a particular call.
Note
This sample may not exactly demonstrate some features of the Visual C++ wizards, libraries, and compiler, but it still shows how to complete the intended task.
Keywords
The sample demonstrates the following classes:
CManualAccessor, CErrorsDialog
The sample demonstrates the following interfaces:
IErrorRecords