Microsoft SQL Server 2000 Data Transformation Services- P8

50 390 0
Microsoft SQL Server 2000 Data Transformation Services- P8

Đ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

Other Data Movement and Manipulation Tasks P ART III 326 The File Transfer Protocol (FTP) task allows you to retrieve files from network or Internet sites. The lack of FTP integration was a weakness of DTS in SQL Server 7.0. It didn’t prevent DTS from being used, but it reduced the convenience of the DTS development envi- ronment. You had to coordinate your FTP processes with the execution of your DTS packages, ensuring that the files were moved to the proper directories before the DTS package execution began. Now, with SQL Server 2000, FTP has become another step in the DTS process. N OTE When to Use the File Transfer Protocol (FTP) Task The FTP task can be used to move files or directories in your local network. It can also be used to get files from remote Internet sites. It cannot be used to send files to Internet sites. It would be more convenient if the FTP task could be used to send files to Internet sites as well as getting files. There are tools that make an FTP site appear like a Windows directory. One of these tool, WebDrive ( www.webdrive.com ) is included on the book’s CD. With WebDrive or a similar tool you can use the FTP task to send files to remote Internet sites. T IP When you’re using the FTP task, it’s important to recognize the possibilities for integration with the Dynamic Properties task and with the many ways you can use global variables. You can use the Dynamic Properties task to change the source, the destination, and the files involved with the FTP. You can set these values with global variables that have themselves been set with DTSRun, by another DTS package, by an Execute SQL task, or with an ActiveX Script task. There are times when an ActiveX Script task is more convenient than an FTP task for moving files around your local network. See the discussion of using the FileSystemObject for file and directory manipulation in Chapter 16, “Writing Scripts for an ActiveX Script Task.” 18 0672320118 CH14 11/13/00 5:01 PM Page 326 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Creating the Task and Setting Its Properties You can create the FTP task with the Package Designer or with code. The last section of this chapter has an example of creating the task with code. The FTP Site tab of the File Transfer Protocol Task Properties dialog is shown in Figure 14.1. This is the place where you enter information about the site from which you want to FTP files. The File Transfer Protocol (FTP) Task C HAPTER 14 14 T HE F ILE T RANSFER P ROTOCOL (FTP) T ASK 327 F IGURE 14.1 The FTP task allows you to move files from a local network or from an Internet site. The primary choice you make on the FTP Site tab is the type of source location. You can choose either an Internet site or a network directory. This choice is implemented in code by setting the SourceLocation property to one of the DTSFTPSourceLocation constants: •0— DTSFTPSourceLocation_InternetSite (The default choice) •1— DTSFTPSourceLocation_Directory Most of the other properties you set on the FTP Site fill in the details about the source of the FTP transfer: • SourceSite —Must be used for an Internet source. The property is set to an FTP site name, such as ftp.mcp.com . • SourceUserName —“Anonymous” is used as the default, which is the standard username for making a read-only connection to an Internet FTP site. 18 0672320118 CH14 11/13/00 5:01 PM Page 327 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. • SourcePassword —The email address of the user is often used when connecting as “anonymous.” • NumRetriesOnSource —The number of attempts to be made before the task terminates with a failure. The other property you set on the FTP Site is the directory path, the DestSite property. You have to specify a local network directory for the destination of the FTP task. The FTP Transformation tab, shown in Figure 14.2, lets you choose files from the source that you want to be transferred. The files appear in a list on the left side of the screen. You can move some or all of them over to the list on the right so that they will be included in the transfer. Other Data Movement and Manipulation Tasks P ART III 328 F IGURE 14.2 Choose files to transfer on the FTP Transformation tab. These selections are implemented by the SourceFileName property. This property is a semi- colon-delimited string that contains the filenames, file paths, and file sizes in bytes. The string looks like this: “‘FileOne.dat’;’ftp.mcp.com’;’1234’;’FileTwo.dat’;’ftp.mcp.com’; ➥’4312’;’FileThre.dat’;’ftp.mcp.com’;’314’;” If you specify the site in the SourceSite property, you do not need to include the second para- meter. Also, when you are creating this task programmatically, you do not need to specify the size of the file. You do still need to include the spaces for these values, however. 18 0672320118 CH14 11/13/00 5:01 PM Page 328 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. This string is equivalent to the preceding one if ftp.mcp.com is assigned to the SourceSite property: “‘FileOne.dat’;’’;’’;’FileTwo.dat’;’’;’’;’FileThre.dat’;’’;’’;” The only other choice you have on the FTP Transformation tab is a check box for specifying whether or not files with the same name should be overwritten. This choice is implemented with the NonOverwritable property. This property has a default value of TRUE , which means that files are not overwritten. Creating the Task in Visual Basic I have created a Visual Basic procedure, fctCreateFTPTask , which creates a step, a task, and a custom task for an FTP task. All the properties of the task can be set with this procedure. You can find the code for it in the directory for Chapter 14 on the book’s CD as a Visual Basic Project, with files CreateFTPTask.vbp, CreateFTPTask.frm, and CreateFTPTask.bas. The code for fctCreateFTPTask is shown in Listing 14.1. The procedure needs some utility functions that are included with the code listings on the CD. The project requires references to the Microsoft DTSPackage Object Library and the Microsoft DTS Custom Tasks Object Library. L ISTING 14.1 The Visual Basic Code to Create an FTP Task Option Explicit Public Function fctCreateFTPTask( _ pkg As DTS.Package2, _ Optional sBaseName As String = “FTPTask”, _ Optional sDestSite As String = “C:\Temp”, _ Optional lNumRetriesOnSource As Long = 0, _ Optional sSourceFileName As String = “”, _ Optional lSourceLocation As Long = 0, _ Optional sSourcePassword As String = “”, _ Optional sSourceSite As String = “”, _ Optional sSourceUserName As String = “anonymous”, _ Optional bNonOverwritable As Boolean = True) As String On Error GoTo ProcErr Dim stp As DTS.Step2 Dim tsk As DTS.Task Dim cus As DTSCustTasks.DTSFTPTask The File Transfer Protocol (FTP) Task C HAPTER 14 14 T HE F ILE T RANSFER P ROTOCOL (FTP) T ASK 329 18 0672320118 CH14 11/13/00 5:01 PM Page 329 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ‘Check to see if the selected Base name is unique sBaseName = fctFindUniqueBaseName(pkg, sBaseName) ‘Create task and custom task Set tsk = pkg.Tasks.New(“DTSFTPTask”) Set cus = tsk.CustomTask With cus .Name = “tsk” & sBaseName .Description = sBaseName .NonOverwritable = bNonOverwritable If sDestSite <> “” Then .DestSite = sDestSite End If If sSourceFileName <> “” Then .SourceFilename = sSourceFileName End If If sSourceSite <> “” Then .SourceSite = sSourceSite End If .SourceLocation = lSourceLocation If .SourceLocation = 0 Then If sSourcePassword <> “” Then .SourcePassword = sSourcePassword End If If sSourceUserName <> “” Then .SourceUsername = sSourceUserName End If .NumRetriesOnSource = lNumRetriesOnSource End If End With pkg.Tasks.Add tsk Other Data Movement and Manipulation Tasks P ART III 330 L ISTING 14.1 Continued 18 0672320118 CH14 11/13/00 5:01 PM Page 330 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ‘Create step for task Set stp = pkg.Steps.New With stp .Name = “stp” & sBaseName .Description = sBaseName .TaskName = tsk.Name End With pkg.Steps.Add stp fctCreateFTPTask = stp.Name Set tsk = Nothing Set cus = Nothing Set stp = Nothing ProcExit: Exit Function ProcErr: MsgBox Err.Number & “ - “ & Err.Description fctCreateFTPTask = “” GoTo ProcExit End Function Conclusion The FTP task is a helpful addition to DTS in SQL Server 2000. This task furthers the goal of creating an integrated, RAD environment for data movement and manipulation. The File Transfer Protocol (FTP) Task C HAPTER 14 14 T HE F ILE T RANSFER P ROTOCOL (FTP) T ASK 331 L ISTING 14.1 Continued 18 0672320118 CH14 11/13/00 5:01 PM Page 331 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 18 0672320118 CH14 11/13/00 5:01 PM Page 332 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 15 The Transfer Databases and Other Transfer Tasks IN THIS CHAPTER • When to Use the Transfer Databases and Other Transfer Tasks 334 •Creating the Tasks and Setting Their Properties 335 • The Transfer Databases Task 336 • The Transfer Logins Task 337 • The Transfer Jobs Task 338 • The Transfer Master Stored Procedures Task 339 • The Transfer Error Messages Task 340 •Creating the Tasks in Visual Basic 341 19 0672320118 CH15 11/13/00 4:58 PM Page 333 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Other Data Movement and Manipulation Tasks P ART III 334 The five tasks described in this chapter are the ones used by the Copy Database Wizard to move databases and associated meta data from one SQL Server to a separate SQL Server 2000. It’s important to be able to move meta data along with the transfer of databases. SQL Server stores most of the meta data needed for database manipulation inside each individual database, but there is a significant amount of meta data that is stored in the Master and Msdb system databases. Centralized meta data storage makes it possible for the meta data to be used by all the data- bases on a server. But the centralized meta data becomes a problem when you move an indi- vidual database to a new server. Unless you include all the needed meta data, the database will not operate properly on its new server. Each of the four additional transfer tasks involves the movement of a particular kind of data: • Logins, stored in master • System stored procedures, stored in master •Error messages, stored in master •Jobs, stored in msdb The most common difficulty I have seen in moving databases is getting all the logins moved properly. But all the meta data is important. Stored procedures, scheduled jobs, and batch processes can all fail if the proper meta data is missing. When to Use the Transfer Databases and Other Transfer Tasks The five transfer tasks are designed for two purposes: • The specific purpose of upgrading a SQL Server 7.0 database to SQL Server 2000. • The more general purpose of moving a database and associated meta data between data- base servers. You can only use databases on SQL Server 7.0 or SQL Server 2000 as the source for these transfer tasks. The destination must be SQL Server 2000. One or more databases can be included in a database transfer. For each included database, you can choose to copy it or move it. You cannot resolve most naming conflicts in the process of using these tasks. You need to resolve any conflicts before setting up these tasks, with the exception of conflicts in the nam- ing of database storage files. 19 0672320118 CH15 11/13/00 4:58 PM Page 334 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. You can include or exclude individual items of meta data, such as particular stored procedures, logins, messages, and jobs. You cannot exclude any of the objects included in the databases being transferred. If you just want to transfer some objects in a database, you should consider using the Copy SQL Server Objects task. If you want to modify the data as it is being moved, you should consider using one of the transformation tasks. These five tasks are the ones to use when you want to move or copy one or more whole data- bases. Creating the Tasks and Setting Their Properties The primary method of creating these tasks is to use the Copy Database Wizard, which is described in Chapter 25. You can also create the tasks in the Package Designer, although this is not as convenient as using the wizard. It is possible to create these tasks in code, but the object model for these tasks is not as well documented as the object model for the other DTS tasks. Most of the properties for these objects are not displayed with Disconnected Edit. The last section of this chapter shows how to create the basic tasks in code. The Source and the Destination for the Tasks All five of the transfer tasks have similar properties for the source and destination. Figure 15.1 shows the Source tab for the Transfer Databases task. The Transfer Databases and Other Transfer Tasks C HAPTER 15 335 15 T HE T RANSFER D ATABASES AND O THER T RANSFER T ASKS F IGURE 15.1 All five transfer tasks have the same tabs for entering source and destination server information. The transfer tasks do not use DTS connections. Instead, the connection information must be entered for both source and destination in the task’s properties dialog. 19 0672320118 CH15 11/13/00 4:58 PM Page 335 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... task to delete the source database files after the databases have been moved You are not allowed to transfer a database if • The destination has a database with the same name • The database is involved in replication The Transfer Databases and Other Transfer Tasks CHAPTER 15 337 • The source is a SQL Server in Windows 2000 and the destination is a SQL Server in Windows 98 • The database is unavailable... The Transfer Databases dialog shows you which databases you are allowed to copy or move NOTE If you move a database, that database won’t be available on the source server after the step is executed The database files on the source server are not removed, however Whether you copy or move a database with the Copy Databases task, after the task is executed there will be a copy of all the database files... selected databases only, the list of choices is enabled, as shown in Figure 15.4 NOTE 15 THE TRANSFER DATABASES AND OTHER TRANSFER TASKS When you’re transferring databases, it’s sometimes reasonable to include only the logins that are being used in those databases After all, if certain logins aren’t using those databases on the old server, why should those logins need to be transferred? 338 Other Data. .. unless you are moving all the databases on a server If a job involves a database that is not being moved, that job will fail if it is executed on a different server The Transfer Databases and Other Transfer Tasks CHAPTER 15 339 If you want to view details of the jobs you are considering transferring, they are listed in the Enterprise Manager tree under the Management \SQL Server Agent node The Transfer...336 Other Data Movement and Manipulation Tasks PART III NOTE This is one of the reasons why using the wizard is appealing You enter the source and destination information once, and it is used for all of the tasks The Transfer Database Task The Databases tab of the Transfer Databases dialog, shown in Figure 15.2, is the place where you choose which databases to copy and which databases to move... inadequate space to copy the database to the default data location FIGURE 15.3 You can modify the destination files for the databases while you are creating the task The Transfer Logins Task You have two basic options on the Logins tab of the Transfer Logins dialog: • Include all server logins detected at package runtime • Include logins for selected databases The other meta data transfer tasks have similar... which of the Master database’s stored procedures to transfer If you create a stored procedure in the Master database and it is named with an sp_ prefix, that stored procedure can be executed from all the databases on a server as if it were local A stored procedure created like this is called a system stored procedure There are many system stored procedures that are included with SQL Server These procedures... pkg.Tasks(“tskUpdateAuthors”) ‘An Execute SQL task Set cus = tsk.CustomTask Msgbox cus.SQLStatement ‘One way to reference custom task properties Msgbox tsk.Properties(“SQLStatement”).Value ‘The other way Msgbox tsk.SQLStatement ‘This Will Not Work! Referencing the Collections and Objects in a Transform Data Task You can continue in a similar way through the object hierarchy The transformation tasks are more complex... book’s CD as a Visual Basic Project, with files CreateTransferDatabaseTask.frm, CreateTransferDatabaseTask.bas, and CreateTransferDatabaseTask.vbp The code for fctCreateTransferDatabaseTask is shown in Listing 15.1 The procedure needs some utility functions that are included with the code listings on the CD The project requires references to the Microsoft DTSPackage Object Library and the OMWCustomTasks... to Create a Transfer Databases Task Public Function fctCreateTransferDatabaseTask( _ pkg As DTS.Package2, _ Optional sBaseName As String = “TransferDatabaseTask” _ ) As String On Error GoTo ProcErr Dim stp As DTS.Step2 Dim tsk As DTS.Task Dim cus As OMWTransferDatabases ‘Check to see if the selected Base name is unique sBaseName = fctFindUniqueBaseName(pkg, sBaseName) THE TRANSFER DATABASES AND OTHER . meta data from one SQL Server to a separate SQL Server 2000. It’s important to be able to move meta data along with the transfer of databases. SQL Server. upgrading a SQL Server 7.0 database to SQL Server 2000. • The more general purpose of moving a database and associated meta data between data- base servers.

Ngày đăng: 20/10/2013, 17:15

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan