home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Run_a_SQL_400771272001.psc / DTSPackages.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-12-07  |  13.0 KB  |  393 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form DTSPackages 
  4.    Caption         =   "DTS Packages Test"
  5.    ClientHeight    =   4905
  6.    ClientLeft      =   5175
  7.    ClientTop       =   3645
  8.    ClientWidth     =   7200
  9.    Icon            =   "DTSPackages.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4905
  12.    ScaleWidth      =   7200
  13.    StartUpPosition =   2  'CenterScreen
  14.    Begin VB.ListBox ssdbDTSPkgs 
  15.       Height          =   3960
  16.       ItemData        =   "DTSPackages.frx":030A
  17.       Left            =   90
  18.       List            =   "DTSPackages.frx":030C
  19.       MultiSelect     =   1  'Simple
  20.       Sorted          =   -1  'True
  21.       TabIndex        =   15
  22.       Top             =   465
  23.       Width           =   4365
  24.    End
  25.    Begin VB.ComboBox cboServers 
  26.       Enabled         =   0   'False
  27.       Height          =   315
  28.       Left            =   4620
  29.       TabIndex        =   14
  30.       Top             =   3000
  31.       Width           =   2430
  32.    End
  33.    Begin MSComctlLib.StatusBar sb 
  34.       Align           =   2  'Align Bottom
  35.       Height          =   345
  36.       Left            =   0
  37.       TabIndex        =   13
  38.       Top             =   4560
  39.       Width           =   7200
  40.       _ExtentX        =   12700
  41.       _ExtentY        =   609
  42.       _Version        =   393216
  43.       BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
  44.          NumPanels       =   1
  45.          BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  46.             AutoSize        =   1
  47.             Object.Width           =   12277
  48.          EndProperty
  49.       EndProperty
  50.    End
  51.    Begin VB.Frame frmDSN 
  52.       Caption         =   "DSN or DSN Less?"
  53.       Height          =   690
  54.       Left            =   4620
  55.       TabIndex        =   8
  56.       Top             =   360
  57.       Width           =   2475
  58.       Begin VB.OptionButton DSNLess 
  59.          Height          =   270
  60.          Left            =   1200
  61.          TabIndex        =   10
  62.          Top             =   285
  63.          Width           =   285
  64.       End
  65.       Begin VB.OptionButton DSN 
  66.          Height          =   270
  67.          Left            =   150
  68.          TabIndex        =   9
  69.          Top             =   285
  70.          Width           =   285
  71.       End
  72.       Begin VB.Label Label2 
  73.          AutoSize        =   -1  'True
  74.          Caption         =   "DSN-Less"
  75.          Height          =   195
  76.          Left            =   1485
  77.          TabIndex        =   12
  78.          Top             =   315
  79.          Width           =   720
  80.       End
  81.       Begin VB.Label lblDSN 
  82.          AutoSize        =   -1  'True
  83.          Caption         =   "DSN"
  84.          Height          =   195
  85.          Left            =   435
  86.          TabIndex        =   11
  87.          Top             =   315
  88.          Width           =   345
  89.       End
  90.    End
  91.    Begin VB.TextBox txtPwd 
  92.       Enabled         =   0   'False
  93.       Height          =   330
  94.       IMEMode         =   3  'DISABLE
  95.       Left            =   4620
  96.       PasswordChar    =   "*"
  97.       TabIndex        =   5
  98.       ToolTipText     =   "Password for Login to Server"
  99.       Top             =   4095
  100.       Width           =   1950
  101.    End
  102.    Begin VB.TextBox txtLogin 
  103.       Enabled         =   0   'False
  104.       Height          =   330
  105.       Left            =   4620
  106.       TabIndex        =   4
  107.       ToolTipText     =   "Login ID for Server"
  108.       Top             =   3525
  109.       Width           =   1950
  110.    End
  111.    Begin VB.CommandButton cmdRunDTSPkg 
  112.       Caption         =   "Run DTS Pkg"
  113.       Enabled         =   0   'False
  114.       Height          =   420
  115.       Left            =   5895
  116.       TabIndex        =   1
  117.       Top             =   1200
  118.       Width           =   1290
  119.    End
  120.    Begin VB.CommandButton cmdGetDTSList 
  121.       Caption         =   "List DTS Pkgs"
  122.       Enabled         =   0   'False
  123.       Height          =   420
  124.       Left            =   4620
  125.       TabIndex        =   0
  126.       Top             =   1200
  127.       Width           =   1290
  128.    End
  129.    Begin DTSList.EBDSNCombo txtDSNName 
  130.       Height          =   315
  131.       Left            =   4620
  132.       TabIndex        =   17
  133.       Top             =   2325
  134.       Width           =   2415
  135.       _ExtentX        =   4260
  136.       _ExtentY        =   556
  137.       Enabled         =   0   'False
  138.       Enabled         =   0   'False
  139.    End
  140.    Begin VB.Label lblRider 
  141.       Caption         =   "You can List the DTS Packages from a DSN, but you must fill in the Server Name, Login ID and Password to run a chosen Package."
  142.       BeginProperty Font 
  143.          Name            =   "Arial"
  144.          Size            =   8.25
  145.          Charset         =   0
  146.          Weight          =   400
  147.          Underline       =   0   'False
  148.          Italic          =   0   'False
  149.          Strikethrough   =   0   'False
  150.       EndProperty
  151.       Height          =   1005
  152.       Left            =   4500
  153.       TabIndex        =   18
  154.       Top             =   1650
  155.       Visible         =   0   'False
  156.       Width           =   2685
  157.    End
  158.    Begin VB.Label lblDTSPackagesList 
  159.       AutoSize        =   -1  'True
  160.       Caption         =   "DTS Packages will be shown below:"
  161.       BeginProperty Font 
  162.          Name            =   "Arial"
  163.          Size            =   8.25
  164.          Charset         =   0
  165.          Weight          =   700
  166.          Underline       =   0   'False
  167.          Italic          =   0   'False
  168.          Strikethrough   =   0   'False
  169.       EndProperty
  170.       Height          =   210
  171.       Left            =   105
  172.       TabIndex        =   16
  173.       Top             =   225
  174.       Width           =   2955
  175.    End
  176.    Begin VB.Label lblPassword 
  177.       AutoSize        =   -1  'True
  178.       Caption         =   "Password:"
  179.       Enabled         =   0   'False
  180.       Height          =   195
  181.       Left            =   4620
  182.       TabIndex        =   7
  183.       Top             =   3870
  184.       Width           =   735
  185.    End
  186.    Begin VB.Label lblID 
  187.       AutoSize        =   -1  'True
  188.       Caption         =   "Login ID:"
  189.       Enabled         =   0   'False
  190.       Height          =   195
  191.       Left            =   4620
  192.       TabIndex        =   6
  193.       Top             =   3315
  194.       Width           =   645
  195.    End
  196.    Begin VB.Line Line2 
  197.       BorderWidth     =   2
  198.       DrawMode        =   1  'Blackness
  199.       X1              =   4620
  200.       X2              =   7140
  201.       Y1              =   2730
  202.       Y2              =   2730
  203.    End
  204.    Begin VB.Label lblDTSSvrNAme 
  205.       AutoSize        =   -1  'True
  206.       Caption         =   "DTS Server Name:"
  207.       Enabled         =   0   'False
  208.       Height          =   195
  209.       Left            =   4620
  210.       TabIndex        =   3
  211.       Top             =   2775
  212.       Width           =   1350
  213.    End
  214.    Begin VB.Label lblDSNNameMSDB 
  215.       AutoSize        =   -1  'True
  216.       Caption         =   "DSN Name to msdb database:"
  217.       Enabled         =   0   'False
  218.       Height          =   195
  219.       Left            =   4620
  220.       TabIndex        =   2
  221.       Top             =   2085
  222.       Width           =   2160
  223.    End
  224.    Begin VB.Menu m_File 
  225.       Caption         =   "&File"
  226.       Begin VB.Menu m_About 
  227.          Caption         =   "About"
  228.       End
  229.       Begin VB.Menu m_Spacer 
  230.          Caption         =   "-"
  231.       End
  232.       Begin VB.Menu m_Exit 
  233.          Caption         =   "Exit"
  234.       End
  235.    End
  236. Attribute VB_Name = "DTSPackages"
  237. Attribute VB_GlobalNameSpace = False
  238. Attribute VB_Creatable = False
  239. Attribute VB_PredeclaredId = True
  240. Attribute VB_Exposed = False
  241. 'This object is set up to retrieve the Server listing for SQL
  242. Private objApplication As New SQLDMO.Application
  243. Private Sub cmdGetDTSList_Click()
  244.     Dim cnn As ADODB.Connection
  245.     Dim rst As ADODB.Recordset
  246.     Dim sSQL As String
  247.     On Error GoTo Err_Trap
  248.     If DSN.Value = True Then
  249.         If Len(txtDSNName.DSN) = 0 Then
  250.             MsgBox "Choose a DSN!", , "Nothing Chosen"
  251.             Exit Sub
  252.         End If
  253.     ElseIf DSNLess.Value = True Then
  254.         If Len(cboServers.Text) = 0 Or Len(txtLogin.Text) = 0 Then
  255.             MsgBox "Choose a Server and Login", , "Nothing Chosen"
  256.             Exit Sub
  257.         End If
  258.     End If
  259.     'Here we select the name of the packages from the msdb database sysdtspackages table
  260.     sSQL = "SELECT DISTINCT name FROM sysdtspackages"
  261.     Set cnn = New ADODB.Connection
  262.     Set rst = New ADODB.Recordset
  263.     sb.SimpleText = "Running......."
  264.     If DSN.Value = True Then
  265.         With cnn
  266.             .ConnectionString = "DATA SOURCE=" & txtDSNName.DSN
  267.             .CursorLocation = adUseClient
  268.             .Open
  269.             'process the stored procedure command with no records to return
  270.             Set rst = .Execute(sSQL)
  271.         End With
  272.     Else
  273.         With cnn
  274.             .ConnectionString = "driver={SQL Server};server=" & cboServers.Text & ";uid=" & txtLogin.Text & ";pwd=" & txtPwd.Text & ";database=msdb"
  275.             .ConnectionTimeout = 30
  276.             .Open
  277.             Set rst = .Execute(sSQL)
  278.         End With
  279.     End If
  280.     ssdbDTSPkgs.Clear
  281. '**********************************
  282.     'Load the listbox
  283.     While Not rst.EOF
  284.         With ssdbDTSPkgs
  285.             .AddItem rst("name").Value
  286.         End With
  287.         rst.MoveNext
  288.     Wend
  289. '**********************************
  290.     If DSN.Value = True Then
  291.         lblDTSPackagesList.Caption = "DTS Packages for DSN: " & txtDSNName.DSN
  292.     ElseIf DSNLess.Value = True Then
  293.         lblDTSPackagesList.Caption = "DTS Packages on Server: " & cboServers.Text
  294.     End If
  295.     DSNLess.Value = True
  296.     Call DSNLess_Click
  297.     Set rst = Nothing
  298.     Set cnn = Nothing
  299.     sb.SimpleText = "Finished!"
  300. Exit_Sub:
  301.     Exit Sub
  302. Err_Trap:
  303.     MsgBox "You possibly entered a Server or DSN" & vbCrLf & "that doesn't have DTS Packages or a name that doesn't exist" & vbCrLf & vbCrLf _
  304.     & "Check your values and try again!", vbCritical, "Problem with entries"
  305. End Sub
  306. Private Sub cmdRunDTSPkg_Click()
  307.     Dim myDTS As DTS.Package
  308.     Dim intSel As Long
  309.     Dim X As Long
  310.     intSel = ssdbDTSPkgs.SelCount
  311.     If Len(cboServers.Text) = 0 Or Len(txtLogin.Text) = 0 Then
  312.         MsgBox "Choose a Server and Login", , "Nothing Chosen"
  313.         Exit Sub
  314.     End If
  315.     For X = 1 To intSel
  316.         Set myDTS = New DTS.Package
  317.         sb.SimpleText = "Running......."
  318.         myDTS.LoadFromSQLServer cboServers.Text, txtLogin.Text, txtPwd.Text, 256, , , , ssdbDTSPkgs.List(X)
  319.         ' Set ExecuteInMainThread for ALL Steps
  320.         Dim i As Integer
  321.         For i = 1 To myDTS.Steps.Count
  322.             myDTS.Steps(i).ExecuteInMainThread = True
  323.         Next i
  324.         'execute all step in the DTS Package
  325.         myDTS.Execute
  326.         sb.Font.Bold = True
  327.         sb.SimpleText = "Finished!"
  328.     Next
  329.     myDTS.UnInitialize
  330.     Set myDTS = Nothing
  331.     frmDSN.Enabled = True
  332. End Sub
  333. Private Sub cmdRunDTSPkg_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  334.     txtDSNName.Visible = False
  335.     lblRider.Visible = True
  336. End Sub
  337. Private Sub DSN_Click()
  338.     lblDSNNameMSDB.Enabled = True
  339.     cmdGetDTSList.Enabled = True
  340.     txtDSNName.Enabled = True
  341.     lblDTSSvrNAme.Enabled = False
  342.     lblID.Enabled = False
  343.     cboServers.Enabled = False
  344.     txtLogin.Enabled = False
  345.     txtPwd.Enabled = False
  346.     lblPassword.Enabled = False
  347. End Sub
  348. Private Sub DSNLess_Click()
  349.     lblDSNNameMSDB.Enabled = False
  350.     txtDSNName.Enabled = False
  351.     cmdGetDTSList.Enabled = True
  352.     lblDTSSvrNAme.Enabled = True
  353.     lblID.Enabled = True
  354.     lblPassword.Enabled = True
  355.     cboServers.Enabled = True
  356.     txtLogin.Enabled = True
  357.     txtPwd.Enabled = True
  358. End Sub
  359. Private Sub Form_Load()
  360.     'Get a list of Servers from my Server group using the SQLDMO
  361.     'This code is compliments of Jeremy van Dijk who has listed the
  362.     'SQL Scripter Tool on www.planet-source-code.com
  363.     Dim objServerGroup As SQLDMO.ServerGroup
  364.     Dim objRegisteredServer As SQLDMO.RegisteredServer
  365.     Dim i As Integer, j As Integer
  366.     For Each objServerGroup In objApplication.ServerGroups
  367.         For Each objRegisteredServer In objServerGroup.RegisteredServers
  368.             cboServers.AddItem objRegisteredServer.Name
  369.             cboServers.ItemData(cboServers.NewIndex) = CStr(objRegisteredServer.UseTrustedConnection)
  370.         Next objRegisteredServer
  371.     Next objServerGroup
  372.     txtDSNName.DriverFilter = "SQL Server"
  373.     DSN.Value = False
  374.     DSNLess.Value = False
  375. End Sub
  376. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  377.     txtDSNName.Visible = True
  378.     lblRider.Visible = False
  379. End Sub
  380. Private Sub m_About_Click()
  381.     Me.Hide
  382.     Load DTSAbout
  383.     DTSAbout.Show
  384. End Sub
  385. Private Sub m_Exit_Click()
  386.     Unload Me
  387. End Sub
  388. Private Sub ssdbDTSPkgs_Click()
  389.     If ssdbDTSPkgs.ListCount > 0 Then
  390.         cmdRunDTSPkg.Enabled = True
  391.     End If
  392. End Sub
  393.