1. Trang chủ
  2. » Công Nghệ Thông Tin

access 2007 vba bible phần 10 doc

73 201 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 73
Dung lượng 2,74 MB

Nội dung

If you don’t have SQL Server 2005 installed, you can download the Express version free, from http://msdn.microsoft.com/vstudio/express/sql/. Compared to the full version, SQL Server 2005 Express (SSE) has a number of limitations, but it is fine for experimenting with SQL Server as a back end, or developing small applications. SSE includes all the core database features of SQL Server 2005, but it lacks support for enterprise fea- tures. If you need to create an enterprise application, you will need one of the other editions of SQL Server 2005, but for individual or small business use, SSE is very suitable. For a full comparison of the features of the five editions of SQL Server 2005, see the tables here: www.microsoft.com/sql/prodinfo/features/compare- features.mspx . SSE is an upgrade to the Microsoft Database Engine (MSDE), which was included in the higher- end editions of previous Office versions. Compared to MSDE, SSE has several enhancements: n The maximum database size has doubled, from 2GB to 4GB. n MSDE’s limitation on the number of concurrent users to five (with performance degrad- ing significantly if there were more users) has been removed. n The SQL Server Management Studio (included with SSE) gives you a user-friendly inter- face for working with saved queries and stored procedures, as well as various administra- tive tasks. n The new XCopy deployment feature allows you to copy a database file to another com- puter, even if the database is not open. Other users can then connect to the database copy using the AttachDBFileName connection string argument. SQL Server 2005 must be upgraded to Service Pack 2 to work with Access 2007. If you have an earlier version, when you first run SQL Server 2005, or attempt to connect to it, you will get a message advising you of the need to upgrade, with a reference to a web page with the SP2 upgrade links for both SQL Server 2005 and SSE. Preparing an Access Database for Upsizing to SQL Server To convert an Access database (or just its tables) to SQL Server (this is known as upsizing), you need to run the Upsizing Wizard, as described in the “Using the Upsizing Wizard” section later in this chapter. However, before you run the Upsizing Wizard to upsize an Access database to SQL Server 2005 or SSE, you need to make some preparations in your database: n Make sure that each table has a unique index, because a SQL Server can’t update a table that lacks a unique index. n Make any hidden tables visible (see sidebar that follows), because the Upsizing Wizard can’t upsize hidden tables. n Compile all the code, and correct any errors. NOTE NOTE NOTE NOTE 629 Working with SQL Server Data 18 24_047026 ch18.qxp 4/2/07 9:57 PM Page 629 630 Adding More Functionality to Office Part III Making Hidden Tables Visible T o make hidden tables visible, click File ➪ Access Options, select the Current Database page, and click the Navigation Options button: The Navigation Options button on the Current Database page of the Access Options dialog. On the Navigation Options dialog, check the “Show Hidden Options” checkbox: Making hidden objects visible in the Navigation Options dialog. 24_047026 ch18.qxp 4/2/07 9:57 PM Page 630 You may have code in an Access database that was originally created many versions ago, but you haven’t upgraded it because it still runs. Before upsizing to SQL Server, you should make sure that all your code is up to date, because SQL Server is much less forgiving than Access. I made a sample database for this chapter, Basic Northwind.accdb, based on the old Northwind sample database that came with several previous versions of Access. Because Northwind was origi- nally created many versions ago, and has only been minimally upgraded over Access versions, there is a good deal of old code in this database — some of it very old code indeed: Access 95 or earlier. Before upsizing, I took the opportunity to update all the code to the current syntax. For example, the old Northwind code uses the IsLoaded function, provided in a module. Many versions of Access ago, this function was needed, but since Access 2000, you don’t need a special function to check whether a form is loaded — just use the IsLoaded property of the form, as an item in the AllForms collection. Here is some typical code for returning to the main menu, as used in a standard Form_Close event procedure: Dim prj As Object Set prj = Application.CurrentProject If prj.AllForms(“fmnuMain”).IsLoaded = True Then Forms![fmnuMain].Visible = True Else DoCmd.OpenForm “fmnuMain” End If Some features that are supported in Access applications won’t survive upsizing, unfortunately. Functions called from calculated expressions in queries are not supported in SQL Server, so when you upsize a query that uses functions in calculated field expressions, you will get an error. I rec- ommend removing the functions from query calculated expressions before upsizing; after the data- base is upsized, you can modify the corresponding stored procedure or user-defined function as needed in a way that will work in SQL Server. Configuring SQL Server 2005 for Data Access In Access 2003, you didn’t need to do any special SQL Server setup before upsizing an Access database to SQL Server using the Microsoft Database Engine (MSDE), the predecessor to SQL Server 2005 Express. But the situation in Office 2007 is very different. In addition to preparing your Access database, you also have a considerable number of setup chores to do to make SQL 631 Working with SQL Server Data 18 24_047026 ch18.qxp 4/2/07 9:57 PM Page 631 632 Adding More Functionality to Office Part III SQL Server Books Online Y ou can download a set of books on SQL Server 2005 from www.microsoft.com/technet/ prodtechnol/sql/2005/downloads/books.mspx . Once downloaded and installed, you can open the SQL Server Books Online from the newly created Documentation and Tutorials group under the Microsoft SQL Server 2005 program group: Opening SQL Server Books Online Help. 24_047026 ch18.qxp 4/2/07 9:57 PM Page 632 Server (or SSE) available as a back end for Access. By default, when SQL Server (or SSE) is installed, it may not be set to run on startup. To ensure that SQL Server is running and available, follow these steps: 1. Open the SQL Server Configuration Manager from the SQL Server (or SSE) group on the Start menu, as shown in Figure 18.2. 2. Select SQL Server 2005 Services in the left pane of the SQL Server Configuration Manager (Figure 18.3). In Vista, you may get a User Account Control (UAC) message. If so, just click Continue. 633 Working with SQL Server Data 18 The books include documentation for both the regular version of SQL Server 2005 and SSE: The Contents page of SQL Server Books Online. If you have upgraded SQL Server 2005 to Service Pack 2, make sure to also download the equivalent upgrade for SQL Server Books Online (available from the same web page as the SP2 patch for SQL Server, www.microsoft.com/sql/ctp.mspx), so the documentation will reflect the SP2 changes. 24_047026 ch18.qxp 4/2/07 9:57 PM Page 633 FIGURE 18.2 Selecting the SQL Server Configuration Manager item on the Start menu. FIGURE 18.3 Selecting the SQL Server 2005 Services page in the SQL Server Configuration Manager. 634 Adding More Functionality to Office Part III 24_047026 ch18.qxp 4/2/07 9:57 PM Page 634 3. As depicted in Figure 18.4, right-click the SQL Server (SQLEXPRESS) row and select Properties. The selection is “SQL Server (SQLEXPRESS)” even if you are running the regular edition of SQL Server 2005. FIGURE 18.4 Opening the SQL Server (SQLEXPRESS) properties sheet. 4. Select the Service tab in the properties sheet. 5. If the start mode is not automatic, drop down the Start Mode list and select Automatic, as in Figure 18.5. FIGURE 18.5 Selecting the Automatic start mode for SQL Server. NOTE NOTE 635 Working with SQL Server Data 18 24_047026 ch18.qxp 4/2/07 9:57 PM Page 635 6. Click OK. Next, right-click the SQL Server Browser row and select Properties. 7. Click the Service tab and set the Start Mode attribute to Automatic if needed, similar to step 5. 8. If you had to set the start mode to Automatic, and the state of the Browser was stopped, start it manually by right-clicking the SQL Server Browser row and selecting Start (Figure 18.6). FIGURE 18.6 Manually starting the SQL Server Browser. 9. You will get a progress bar (see Figure 18.7) as the SQL Server service is started. FIGURE 18.7 Starting the SQL Server service. 636 Adding More Functionality to Office Part III 24_047026 ch18.qxp 4/2/07 9:57 PM Page 636 Next, you must enable network access — this is required even if you are connecting to SQL Server on the same computer. 1. Start by expanding the SQL Server 2005 Network Configuration folder in the left pane of the SQL Server Configuration Manager, and select the Protocols for SQLEXPRESS folder under it. 2. Enable the TCP/IP protocol from its right-click menu (Figure 18.8). FIGURE 18.8 Enabling the TCP/IP protocol. 3. You will get a message, shown in Figure 18.9, that you have to stop and restart the serv- ice. You can do this by right-clicking SQL Server (SQLEXPRESS) in the SQL Server 2005 Services folder and selecting Restart, or by shutting down and restarting Windows. FIGURE 18.9 A warning after enabling a protocol. 4. If your connection makes use of the Named Pipes protocol, you can enable it in a sim- ilar fashion. 637 Working with SQL Server Data 18 24_047026 ch18.qxp 4/2/07 9:57 PM Page 637 Next, you have to configure SQL Server to allow remote connections (for some reason, this is nec- essary even if you have installed SQL Server on the same computer as Access): 1. Select SQL Server Surface Area Configuration (see Figure 18.10) from the Configuration Tools group in the Microsoft SQL Server 2005 program group. If you are running Vista, you may get a message that the program has known compatibility issues. If so, you need to install the SP2 service pack for SQL Server 2005. FIGURE 18.10 The SQL Server 2005 Surface Area Configuration dialog. 2. Click the Surface Area Configuration for Services and Connections item (see Figure 18.10). 3. Expand the Database Engine item (if necessary) and click Remote Connections. 4. Select Local and Remote connections, and select the appropriate protocol, usually “Using TCP/IP only” (Figure 18.11). 638 Adding More Functionality to Office Part III 24_047026 ch18.qxp 4/2/07 9:57 PM Page 638 [...]... Protection warning Using the Upsizing Wizard Access 2007 includes a handy tool for converting Access tables to SQL Server tables and (if desired) some Access queries to SQL Server stored procedures: the Upsizing Wizard You can take a minimalist approach, and just convert your Access tables to SQL Server tables linked to the Access database, using the familiar Access interface as a front end; or you can... extension The Access front end now has two sets of tables: the original (pre-upsizing) Access tables, renamed with the suffix _local, and the linked SQL server tables, as shown in Figure 18.38 The SQL Server tables are indicated by the arrow and globe icon FIGURE 18.38 Linked SQL Server tables in the upsized Access database In the Access front-end database, forms and reports should work as with local Access. .. and Sample Databases (February 2007) page on the Microsoft web site, at this link: www.microsoft.com/ downloads/details.aspx?FamilyID=e719ecf7-9f46-4312-af89-6ad8702e4e6e& DisplayLang=en#filelist (or possibly a page with a later date) Make sure that any sample databases you download are compatible with Access 2007 Those on the December 2006 page are compatible with Access 2007; other sample databases... FIGURE 18.39 An Access form displaying data from a linked SQL Server table Creating a Client/Server Application Compared with just converting the tables to SQL Server tables, and linking the Access database to them as a front end, creating an Access Project as a front end has several advantages: You can make design changes to SQL Server tables and views, some of which can’t be edited from an Access front... of the database to a project with a SQL Server back end Converting just the tables is fine if you intend to use your Access forms, queries, and reports in an Access front end, and you just want to store your data in a SQL Server back end If you want to convert your Access database to an Access project front end with a SQL Server back end so that you can make design changes to SQL Server tables and views... objects, such as database diagrams, stored procedures, and user-defined functions In a linked Access front end, by contrast, you can’t make design changes to any SQL Server objects, and you can only link to SQL Server tables and views To create a client/server application from an Access database, with an Access Project (.adp) as the front end to the SQL Server back end, proceed as in the previous section... now have a client/server application consisting of an Access project front end and a SQL Server back end; from this point on you will need to use SQL Server techniques to work with the project and the back-end tables 660 Working with SQL Server Data FIGURE 18.45 Four upsized queries in an Access project FIGURE 18.46 A SQL Server view created from an Access query 661 18 Part III Adding More Functionality... to Office FIGURE 18.47 A user-defined function created from an Access query Linking to Data in SQL Server Tables You may need to connect to SQL Server databases for a company, university, or other organization that stores its data in SQL Server If you need to link an Access database to data in existing SQL Server tables, or create a new Access front end for SQL Server tables, the process is different... information that would help with the decision to use the existing database or create a new one, you get the main Access Help screen, with a Table of Contents and a Search box This is not an improvement over previous versions of Access, where context-specific Help was generally available in wizards In Access 2003, for example, if you run the Upsizing Wizard and click the Help button on the first screen, you... following sections explain how to get through the Windows XP and Windows Vista firewalls, respectively Windows XP Follow these steps to allow access to SQL Server through the Windows XP firewall: NOTE If you are using another firewall, the steps needed to allow access to SQL Server will be somewhat different 1 Open the Security Center from the Control Panel, and click the Windows Firewall item (see Figure . Protection warning. Using the Upsizing Wizard Access 2007 includes a handy tool for converting Access tables to SQL Server tables and (if desired) some Access queries to SQL Server stored procedures:. use your Access forms, queries, and reports in an Access front end, and you just want to store your data in a SQL Server back end. If you want to convert your Access database to an Access project. can take a minimalist approach, and just convert your Access tables to SQL Server tables linked to the Access database, using the familiar Access interface as a front end; or you can convert the

Ngày đăng: 14/08/2014, 06:22

TỪ KHÓA LIÊN QUAN