Microsoft SQL Server 2000 Data Transformation Services- P10

50 459 0
Microsoft SQL Server 2000 Data Transformation Services- P10

Đ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

Control Tasks P ART IV 426 The Execute Process task is one of the least complex of all the DTS tasks. Its only purpose is to run an executable program or a batch file. When to Use the Execute Process Task The importance of the Execute Process task is in the way it integrates DTS packages with other applications and batch processes. Many companies have existing programs that transfer data. You can use DTS as a control panel to run all of your data transformation applications. You can use the various DTS tasks when you want to manipulate data in a new way. You can use the Execute Process task to coordinate your existing data manipulation applications with the rest of what you are doing with DTS. Consider the following specific ways of using the Execute Process task. Bulk Copying from SQL Server to a Text File If you are creating a new bulk copy operation to load SQL Server, I suggest that you use the Bulk Insert task. But you can’t use it if you want to bulk copy data out of SQL Server. However, you can integrate that bulk copy into DTS by using the Execute SQL task. Use the bcp command-line utility to do the bulk copying. Here’s a sample of how to do that. Use the following values in the Execute Process Task dialog: •Win32 Process— bcp •Parameters— out “SELECT au_lname, au_fname as FullName FROM pubs authors ORDER BY au_lname” queryout C:\Authors.txt -c -S(local)-T Figure 22.1 shows the Execute Process Task Properties dialog with the properties set to execute this bulk copy. F IGURE 22.1 You can use the Execute Process task to bulk copy data out of SQL Server into a text file. 27 0672320118 CH22 11/13/00 4:56 PM Page 426 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Executing a Batch File Containing osql and/or bcp Commands If you have existing bcp commands in batch files, whether moving data into or out of SQL Server, you can keep on using those batch files with your DTS package by calling them from the Execute Process task. You can also use osql, the SQL Server command-line utility for executing SQL commands, in these batch files. For example, you could write a batch file that creates a view, uses that view to bulk copy data out of SQL Server, and then drops the view. The file would look like this: osql /S(local) /E /dpubs /Q”create view dbo.vwAuthorName(fullname) ➥as select au_fname + ‘ ‘ + au_lname from pubs.dbo.authors” bcp “pubs.dbo.vwAuthorName” out C:\Temp\AuthorName.txt /c /T /S(local) osql /S(local) /E /dpubs /Q”drop view dbo.vwAuthorName” If you save this batch file as c:\temp\testdts.bat, you would then enter that filename in the Win32 Process of the Execute Process task. You would not use any parameters for the task. Running Other Data Movement or Manipulation Applications You may have external programs that you need to run before or after some of your DTS tasks, such as • Specialized FTP processes that cannot easily be adapted to the DTS FTP task. •Programs that unzip text files. • Applications that convert binary files to text. • Batch files that call OLTP systems to export data. •Programs that process large text files, such as SyncSort. • Customized parsing programs. Executing DTSRun You can execute DTS packages from the Execute Process task by using the DTSRun com- mand-line utility: DTSRun /E /N PackageName /F c:\temp\LoadEmployee.dts The Execute Process Task C HAPTER 22 22 T HE E XECUTE P ROCESS T ASK 427 You have greater control in executing one package from another when you use the Execute Package task. N OTE 27 0672320118 CH22 11/13/00 4:56 PM Page 427 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Creating the Task and Setting Its Properties You can create the Execute Process task in the DTS Designer or in code. Neither of the DTS wizards creates an Execute Process task. The Execute Process Task Properties dialog has only one tab. The dialog lets you set five of the task’s seven properties. You have to use code or Disconnected Edit to view or modify the Name and FailPackageOnTimeout properties. The Execute Process Task Properties Here are the task’s properties: • Name —The name of the task. Cannot be viewed or modified in the Execute Process Task Properties dialog. • Description —The description of the task. • ProcessCommandLine —The command line that is executed. You enter the command line in two boxes in the dialog—the Win32 Process and the parameters. The DTS Designer concatenates the two values to create the value for this property. • SuccessReturnCode —The code that is expected for a successful execution of the appli- cation. If the application returns a different code, the Execute Process task is marked as failed. The default return code is 0. • Timeout —The number of seconds that the Execute Process task waits for a return code from the application. If no return code is received within this time period, the task is marked as failed. The default timeout value is 0, which means that the task will wait indefinitely. • TerminateProcessAfterTimeout —If you specify a value for a time out, you can also choose to terminate the application that was executed when that timeout occurs. Whether or not you terminate the application on timeout, the DTS package will continue its exe- cution. The default value for this property is FALSE . • FailPackageOnTimeout —This property causes the whole DTS package to be terminated if a timeout occurs in the Execute Process task. This value cannot be set or viewed in the dialog. The default value is FALSE . The GetExpandedProcessCommandLine Method of the CreateProcess2 Object In code, the Execute Process task is implemented by the CreateProcess2 object. This object inherits all the properties of the CreateProcess object. Control Tasks P ART IV 428 27 0672320118 CH22 11/13/00 4:56 PM Page 428 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. The CreateProcess2 object adds no new properties, but it does add one method. This method, GetExpandedProcessCommandLine , can be used to return a command line with all parameter variables expanded. For example, you could have a ProcessCommandLine property of bcp pubs.dbo.authors out %TEMP%\authors.txt /c /T /S(local) The GetExpandedProcessCommandLine method would return a value like this: bcp pubs.dbo.authors out C:\Temp\authors.txt /c /T /S(local) Creating the Task in Visual Basic I have created a Visual Basic procedure, fctCreateExecuteProcessTask ,that creates a con- nection, a step, a task, and a custom task for an Execute Process task. All the properties of the task can be set with this procedure. The fctCreateExecuteProcessTask function is used in the DTSPackageGenerator utility that is included with this book. You can also find the procedure in the directory for Chapter 22 as a Visual Basic Project, with files CreateExecuteProcessTask.vbp, CreateExecuteProcessTask.frm, and CreateExecuteProcessTask.bas. The code for fctCreateExecuteProcessTask is shown in Listing 22.1. The procedure needs some utility functions that are included with the code listings on the CD. L ISTING 22.1 The Visual Basic Code to Create an Execute Process Task Option Explicit Public Function fctCreateExecuteProcessTask( _ pkg As DTS.Package2, _ Optional sBaseName As String = “ExecuteProcessTest”, _ Optional sProcessCommandLine As String = “”, _ Optional lSuccessReturnCode As Long = 0, _ Optional lTimeout As Long = 0, _ Optional bTerminateProcessAfterTimeout As Boolean = False, _ Optional bFailPackageOnTimeout As Boolean = False) On Error GoTo ProcErr Dim stp As DTS.Step2 Dim tsk As DTS.Task Dim cus As DTS.CreateProcessTask2 The Execute Process Task C HAPTER 22 22 T HE E XECUTE P ROCESS T ASK 429 27 0672320118 CH22 11/13/00 4:56 PM Page 429 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(“DTSCreateProcessTask”) Set cus = tsk.CustomTask With cus .Name = “tsk” & sBaseName .Description = sBaseName .ProcessCommandLine = sProcessCommandLine .SuccessReturnCode = lSuccessReturnCode .Timeout = lTimeout .TerminateProcessAfterTimeout = bTerminateProcessAfterTimeout .FailPackageOnTimeout = bFailPackageOnTimeout End With pkg.Tasks.Add tsk ‘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 fctCreateExecuteProcessTask = stp.Name Set tsk = Nothing Set cus = Nothing Set stp = Nothing ProcExit: Exit Function ProcErr: MsgBox Err.Number & “ - “ & Err.Description fctCreateExecuteProcessTask = “” GoTo ProcExit End Function Control Tasks P ART IV 430 L ISTING 22.1 Continued 27 0672320118 CH22 11/13/00 4:56 PM Page 430 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Conclusion The Execute Process task is simple, but it is a key player in the integration of DTS with your other data manipulation applications. This is the last chapter discussing the DTS tasks. Part V continues with a discussion of the DTS package as a whole and the steps that control the flow of the tasks. The Execute Process Task C HAPTER 22 22 T HE E XECUTE P ROCESS T ASK 431 27 0672320118 CH22 11/13/00 4:56 PM Page 431 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 27 0672320118 CH22 11/13/00 4:56 PM Page 432 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. IN THIS PART 23 The DTS Package and Its Properties 435 24 Steps and Precedence Constraints 469 25 Rapid Development with the Copy Database Wizard and the DTS Import/Export Wizard 501 26 Managing Packages with Visual Basic and Stored Procedures 525 27 Handling Errors in a Package and Its Transformations 553 28 High Performance DTS Packages 565 29 Integrating DTS with Meta Data Services 587 DTS Packages and Steps PART V 28 0672320118 PT5 11/13/00 5:01 PM Page 433 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 28 0672320118 PT5 11/13/00 5:01 PM Page 434 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 23 The DTS Package and Its Properties IN THIS CHAPTER •Identifying DTS Packages 436 •Storing DTS Packages 438 • Encrypting DTS Packages 444 • Retrieving Information About Packages 445 • Package Logs and Error Files 451 • DTS Packages as Data Sources 460 •Other DTS Package Object Properties and Methods 465 29 0672320118 CH23 11/13/00 5:02 PM Page 435 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... Users must have permission to access the msdb database to save or retrieve the DTS package DTS packages are saved to the SQL Server with the SaveToSQLServer method of the Package object SaveToSQLServer has the following parameters: • ServerName—The • ServerUserName—The logon name for the server specified in ServerName • ServerPassword—The password for the ServerUserName logon • Flags—Security • PackageOwnerPassword—Password... LoadFromSQLServer method is used to retrieve a package that is stored in SQL Server The RemoveFromSQLServer method is used to delete a package from SQL Server storage Their parameters are similar to those used by the saving methods: • ServerName • ServerUserName • ServerPassword • Flags—Optional • PackagePassword—Not • PackageGUID—Optional parameter Uses the constants in Table 23.1 used for RemoveFromSQLServer... Dim DTSApp, PkgSQL, PkgInfos, info, prp, msg 2 Create the Application object: Set DTSApp = CreateObject(“DTS.Application”) 3 Use the GetPackageSQLServer method to log on to a specific SQL Server and obtain a reference to a PackageSQLServer object Four parameters are required—ServerName, UserName, Password, and ConnectionFlags: Set PkgSQL = DTSApp.GetPackageSQLServer(“(local)”, “”, “” _ DTSSQLStgFlag_UseTrustedConnection)... the Logging tab: • LogToSQLServer—Boolean value that determines whether or not the SQL Server logging is enabled • LogServerName—The server used for the logging • LogServerUserName—Username • LogServerPassword—Password • LogServerFlags—One • FailPackageOnLogFailure—Boolean value that determines whether or not the package execution should be terminated with an error if the SQL Server logging process... “(local)”, , , DTSSQLStgFlag_UseTrustedConnection pkg.LoadFromSQLServer “(local)”, , , _ DTSSQLStgFlag_UseTrustedConnection, , , _ , “Test Save And Retrieve Methods” FirstPackageID = pkg.PackageID pkg.Description = “Description to be saved in second package.” pkg.SaveToSQLServerAs “Renamed Package”, “(local)”, , , _ DTSSQLStgFlag_UseTrustedConnection pkg.RemoveFromSQLServer “(local)”, , , _ DTSSQLStgFlag_UseTrustedConnection,... for the Flags Parameter of the SaveToSQLServer Method Constant Value Meaning DTSSQLStgFlag_Default 0 256 Use SQL Server Security Use Trusted Connection DTSSQLStgFlag_UseTrustedConnection The Package2 object has a new method called SaveToSQLServerAs that is used to save a package with a new name and a new Package ID This method has the same parameters as SaveToSQLServer, except for an additional first... String, sServer As String, _ sUserID As String, sPassword As String) As String On Error GoTo ProcErr Dim Dim Dim Dim DTSApp As New DTS.Application PkgSQL As DTS.PackageSQLServer PkgInfos As DTS.PackageInfos info As DTS.PackageInfo Dim lSuffix As Long Dim sModifiedBaseName As String Dim bDupeFound As Boolean ‘Get PackageSQLServer object If sUserID = “” Then Set PkgSQL = DTSApp.GetPackageSQLServer(sServer,... parameter—NewName Saving DTS Packages to SQL Server The definition of a package saved to SQL Server is stored in the sysdtspackages table in the msdb system database The image data type is used to save the package The DTS Package and Its Properties CHAPTER 23 439 Here are the details on saving and retrieving packages when saving to SQL Server: • Packages saved to one instance of SQL Server must have unique names... those for SQL Server packages: • SaveToRepository • SaveToRepositoryAs • LoadFromRepository • RemoveFromRepository Here are the parameters of the SaveToRepository method: • RepositoryServerName—The • RepositoryDatabaseName—The server where this instance of Meta Data Services is stored database where this instance of Meta Data Services is located • RepositoryUserName—The logon name for the server specified... The execution of the following DTS Package failed: Error Source: Microsoft Data Transformation Services (DTS) Package Error Description:Package failed because Step ‘CDW Databases Task Step’ failed Error code: 80040428\Error Help File:sqldts80.hlp Error Help Context ID:700 Package Name: CDW _Server1 _Server2 _3 Package Description: Copy Database Wizard Package Package ID: {AE741877-0433-43C2-A5DB-09BC33ECD47A} . LoadFromSQLServer method is used to retrieve a package that is stored in SQL Server. The RemoveFromSQLServer method is used to delete a package from SQL Server. local server ‘Use integrated security pkg.SaveToSQLServer “(local)”, , , DTSSQLStgFlag_UseTrustedConnection pkg.LoadFromSQLServer “(local)”, , , _ DTSSQLStgFlag_UseTrustedConnection,

Ngày đăng: 24/10/2013, 16:15

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

Tài liệu liên quan