Transfer Tables Between SQL Server Databases - Pdf 76


7.4 Transfer Tables Between SQL Server Databases
Users sometimes need to transfer (copy) tables between SQL Server databases. This
How-To shows how to allow the user to choose multiple tables and copy them from one
database to another as well as tables from two different databases on two different SQL
servers.
One of the tasks your clients have you perform for them using the Enterprise Manager is
to transfer objects, such as tables, between SQL Server databases. How do you create a
dialog box that would allow the user to transfer databases between two SQL Server
databases?
Technique
Unlike the earlier How-Tos in this chapter, you will be using the SQL-DTS object model
in addition to SQL-DMO. You can see the objects, properties, and methods that will be
used from SQL-DTS in Table 7.7.
Table 7.7. SQL-DTS Objects That Are Used to Perform the Transfer of Tables from
One SQL Server Database to Another
Object Property/Method
Package Steps.New
Tasks.New
Steps.Add
Tasks.Add
Execute
Step TaskName
Name
Task CustomTask
CustomTask Name
SourceServer
SourceUseTrustedConnection
SourceDatabase
DestinationServer
DestinationUseTrustedConnection DestinationDatabase

Text From SQL Servers
ListBox Name lstFromSQLServer
Label Name Label2
Text To SQL Servers
ListBox Name lstToSQLServer
Label Name Label3
Text Transfer from Database
ListBox Name lstFromDB
Label Name Label4
Text Transfer to Database
ListBox Name lstToDB
Label Name Label5
Text Table(s) to Transfer
ListBox Name lstTables
SelectionMode MultiSimple
Command Button Name btnTransfer
Text &Perform Transfer
2. On the form, add the code in Listing 7.18 to the Load event. This will look
familiar from How-To 7.1. For an examination of the LoadSQLServers routine,
check out step 4 in that How-To. Different from the other How-Tos in this chapter
thus far, however, is the fact that the LoadSQLServers routine is called twice:
once for the lstFromSQLServer, and a second time for the lstToSQLServer.
Listing 7.18 frmHowTo7_4.vb: Calling the Routine That Loads Available
SQL Servers into a List Box
Private Sub frmHowTo7_4_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

LoadSQLServers(Me.lstFromSQLServer)
LoadSQLServers(Me.lstToSQLServer)


lstBackupDevices List Boxes
Private Sub lstFromDB_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles lstFromDB.SelectedIndexChanged

'-- Create the connection and specify the stored procedure to use.
Dim odb As SQLDMO.Database
Dim otbl As SQLDMO.Table
Dim oapp As New SQLDMO.Application()
Dim osvr As New SQLDMO.SQLServer()

Try

osvr.LoginSecure = True


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status