diff --git a/416.html b/416.html new file mode 100644 index 0000000..3444852 --- /dev/null +++ b/416.html @@ -0,0 +1,11 @@ +Chapter 1: Getting Started with SQL-DMO
+Chapter 2: Backup and Restore: A DBA’s Bread and Butter
+Chapter 3: Managing Users of Your Database and Server
+Chapter 4: Using SQL-DMO with OLE Automation
+Chapter 5: Jobs, Alerts, and Operators
+Chapter 6: Viewing and Setting Server-wide Options
+Chapter 7: Replication and SQL-DMO
+Chapter 8: QALite
+Chapter 9: Using SQL-DMO to Script an Entire Server
+Appendix A SQL-DMO Object Library Quick Reference
+Appendix B Knowledge-Base Articles and Other SQL-DMO Resources \ No newline at end of file diff --git a/672.pdf b/672.pdf new file mode 100644 index 0000000..df1ef99 Binary files /dev/null and b/672.pdf differ diff --git a/674.pdf b/674.pdf new file mode 100644 index 0000000..f6c17f6 Binary files /dev/null and b/674.pdf differ diff --git a/9781590590409.jpg b/9781590590409.jpg new file mode 100644 index 0000000..65e4d91 Binary files /dev/null and b/9781590590409.jpg differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/GentleIntro.csi b/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/GentleIntro.csi new file mode 100644 index 0000000..797bb94 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/GentleIntro.csi @@ -0,0 +1,2 @@ +[History] +B0=GentleIntro/frmIntro/listServers diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/GentleIntro.vbp b/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/GentleIntro.vbp new file mode 100644 index 0000000..f5fec3d --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/GentleIntro.vbp @@ -0,0 +1,41 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\stdole2.tlb#OLE Automation +Reference=*\G{10010001-E260-11CF-AE68-00AA004A34D5}#7.0#0#C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll#Microsoft SQLDMO Object Library +Reference=*\G{420B2830-E718-11CF-893D-00A0C9054228}#1.0#0#C:\WINNT\System32\scrrun.dll#Microsoft Scripting Runtime +Reference=*\G{00000201-0000-0010-8000-00AA006D2EA4}#2.1#0#C:\Program Files\Common Files\System\ADO\msado21.tlb#Microsoft ActiveX Data Objects 2.1 Library +Form=RoleMembers.frm +Object={5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0; MSFLXGRD.OCX +Object={38911DA0-E448-11D0-84A3-00DD01104159}#1.1#0; COMCT332.OCX +IconForm="frmIntro" +Startup="frmIntro" +HelpFile="" +Title="prjSrvRoleMembers" +ExeName32="Nemesis.exe" +Command32="/sapcfpx01" +Name="GentleIntro" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionCompanyName="UBM International" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/GentleIntro.vbw b/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/GentleIntro.vbw new file mode 100644 index 0000000..79e9d61 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/GentleIntro.vbw @@ -0,0 +1 @@ +frmIntro = 87, 74, 1146, 906, C, 0, 0, 0, 0, C diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/MSSCCPRJ.SCC b/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/MSSCCPRJ.SCC new file mode 100644 index 0000000..704501c --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/MSSCCPRJ.SCC @@ -0,0 +1,8 @@ +[SCC] +SCC=This is a source code control file +[prjSrvRoleMembers.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= +[GentleIntro.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/RoleMembers.frm b/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/RoleMembers.frm new file mode 100644 index 0000000..ef721a6 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/A Gentle Introduction/Code/RoleMembers.frm @@ -0,0 +1,718 @@ +VERSION 5.00 +Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX" +Begin VB.Form frmIntro + BackColor = &H0000FFFF& + ClientHeight = 10215 + ClientLeft = 930 + ClientTop = 2595 + ClientWidth = 16755 + LinkTopic = "Form1" + ScaleHeight = 10215 + ScaleWidth = 16755 + Begin VB.CommandButton cmdClear + Caption = "Clear Grid" + Height = 525 + Left = 5610 + TabIndex = 35 + Top = 7710 + Width = 1425 + End + Begin VB.TextBox txtIncrement + Height = 315 + Left = 6510 + TabIndex = 33 + Top = 4530 + Width = 705 + End + Begin VB.TextBox txtSeed + Height = 315 + Left = 5700 + TabIndex = 31 + Top = 4530 + Width = 705 + End + Begin VB.CheckBox chkIdent + BackColor = &H0000C0C0& + Caption = "Identity Col" + Height = 285 + Left = 4320 + TabIndex = 30 + Top = 4530 + Width = 1215 + End + Begin VB.CommandButton cmdAddRelToDB + Caption = "Add to Database" + Height = 405 + Left = 11910 + TabIndex = 27 + Top = 7140 + Width = 3135 + End + Begin VB.CommandButton cmdAddrelgrid + Caption = "Add to grid" + Height = 615 + Left = 12420 + TabIndex = 26 + Top = 4050 + Width = 2535 + End + Begin VB.ListBox lstcol2 + Height = 1425 + Left = 13710 + TabIndex = 25 + Top = 2400 + Width = 2895 + End + Begin VB.ListBox lstcol1 + Height = 1425 + Left = 10740 + TabIndex = 24 + Top = 2400 + Width = 2805 + End + Begin MSFlexGridLib.MSFlexGrid relgrid + Height = 2115 + Left = 10860 + TabIndex = 23 + Top = 4860 + Width = 5295 + _ExtentX = 9340 + _ExtentY = 3731 + _Version = 393216 + Rows = 1 + Cols = 3 + FixedRows = 0 + FixedCols = 0 + AllowUserResizing= 3 + End + Begin VB.ComboBox cbotables2 + Height = 315 + Left = 13650 + TabIndex = 22 + Top = 1470 + Width = 2865 + End + Begin VB.TextBox txtdefault + Height = 315 + Left = 4320 + TabIndex = 20 + Top = 4110 + Width = 2535 + End + Begin VB.OptionButton optKey + BackColor = &H0000C0C0& + Caption = "Primary Key" + Height = 285 + Left = 4350 + TabIndex = 19 + Top = 3420 + Width = 1275 + End + Begin VB.ComboBox cbotables + Height = 315 + Left = 10680 + TabIndex = 17 + Top = 1440 + Width = 2865 + End + Begin VB.TextBox txtcolname + Height = 285 + Left = 150 + TabIndex = 15 + Top = 2640 + Width = 3075 + End + Begin VB.CommandButton cmdAddCol + Caption = "Add Column" + Height = 675 + Left = 3810 + TabIndex = 14 + Top = 5010 + Width = 1515 + End + Begin MSFlexGridLib.MSFlexGrid TableBuilderGrid + Height = 1845 + Left = 120 + TabIndex = 12 + Top = 5730 + Width = 8745 + _ExtentX = 15425 + _ExtentY = 3254 + _Version = 393216 + Rows = 1 + Cols = 9 + FixedRows = 0 + FixedCols = 0 + End + Begin VB.ComboBox cboServers + Height = 315 + Left = 150 + TabIndex = 10 + Top = 1080 + Width = 3285 + End + Begin VB.ComboBox cboDatabases + Height = 315 + Left = 3690 + TabIndex = 8 + Top = 1080 + Width = 3495 + End + Begin VB.CommandButton cmdCreate + Caption = "&Create" + Height = 525 + Left = 7500 + TabIndex = 7 + Top = 7680 + Width = 1395 + End + Begin VB.CheckBox chkNull + BackColor = &H0000C0C0& + Caption = "Nullable" + Height = 375 + Left = 4350 + TabIndex = 6 + Top = 2910 + Width = 1185 + End + Begin VB.TextBox txtLength + Height = 315 + Left = 4320 + TabIndex = 4 + Top = 2520 + Width = 1125 + End + Begin VB.ListBox lstDatatypes + Height = 1620 + Left = 150 + TabIndex = 2 + Top = 3300 + Width = 4065 + End + Begin VB.TextBox txtTableName + Height = 315 + Left = 150 + TabIndex = 0 + Top = 1980 + Width = 3135 + End + Begin VB.Label Label11 + BackColor = &H0000C0C0& + Caption = "Increment" + Height = 285 + Left = 6510 + TabIndex = 34 + Top = 4860 + Width = 795 + End + Begin VB.Label Label10 + BackColor = &H0000C0C0& + Caption = "Seed" + Height = 255 + Left = 5700 + TabIndex = 32 + Top = 4860 + Width = 645 + End + Begin VB.Label Label9 + BackColor = &H0000C0C0& + Caption = "referencing table" + Height = 285 + Left = 13710 + TabIndex = 29 + Top = 2100 + Width = 2355 + End + Begin VB.Label Label8 + BackColor = &H0000C0C0& + Caption = "referenced table" + Height = 285 + Left = 10710 + TabIndex = 28 + Top = 2100 + Width = 2385 + End + Begin VB.Label De + BackColor = &H0000C0C0& + Caption = "Default" + Height = 285 + Left = 4350 + TabIndex = 21 + Top = 3840 + Width = 2235 + End + Begin VB.Label Label7 + Alignment = 2 'Center + BackColor = &H0000C0C0& + Caption = "Tables" + Height = 255 + Left = 12720 + TabIndex = 18 + Top = 690 + Width = 1995 + End + Begin VB.Label Label6 + BackColor = &H0000C0C0& + Caption = "Column Name" + Height = 255 + Left = 150 + TabIndex = 16 + Top = 2460 + Width = 2265 + End + Begin VB.Label Label5 + BackColor = &H0000C0C0& + Caption = "Table Creation" + Height = 315 + Left = 90 + TabIndex = 13 + Top = 5490 + Width = 3675 + End + Begin VB.Label Label4 + BackColor = &H0000C0C0& + Caption = "Servers" + Height = 285 + Left = 150 + TabIndex = 11 + Top = 840 + Width = 2325 + End + Begin VB.Label Label3 + BackColor = &H0000C0C0& + Caption = "Databases" + Height = 255 + Left = 3690 + TabIndex = 9 + Top = 840 + Width = 3135 + End + Begin VB.Label l + BackColor = &H0000C0C0& + Caption = "Length" + Height = 255 + Left = 4320 + TabIndex = 5 + Top = 2280 + Width = 1155 + End + Begin VB.Label Label2 + BackColor = &H0000C0C0& + Caption = "Datatypes" + Height = 225 + Left = 150 + TabIndex = 3 + Top = 3090 + Width = 3315 + End + Begin VB.Label Label1 + BackColor = &H0000C0C0& + Caption = "Table Name" + Height = 315 + Left = 150 + TabIndex = 1 + Top = 1710 + Width = 2565 + End +End +Attribute VB_Name = "frmIntro" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Dim database As SQLDMO.database +Dim server As SQLDMO.SQLServer +Dim srvRole As SQLDMO.ServerRole +Dim dbroles As SQLDMO.DatabaseRole +Dim srvRoleMembers As SQLDMO.QueryResults + +Private Sub cboDatabases_Click() +ListTables cboServers.Text, cboDatabases.Text +ListTables2 cboServers.Text, cboDatabases.Text +End Sub + +Private Sub cboServers_Click() +ListDataBases cboServers.Text +ListDataTypes cboServers.Text +End Sub + +Private Sub AddColToGrid(KeyCol As String, colname As String, datatype As String, collength As String, nullability As String, default As String) + +Dim i As Integer +Dim iCountofids As Integer +Dim idYes As String +iCountofids = 0 + + +'Do we have any id cols already + + For i = 0 To TableBuilderGrid.Rows - 1 + If TableBuilderGrid.TextMatrix(i, 6) = "YES" Then + iCountofids = 1 + End If + Next i + + If iCountofids = 1 And chkIdent.Value = vbChecked Then + MsgBox "You already have an identity Field", vbInformation, "Identity Error" + Exit Sub + End If + + + If chkIdent.Value = vbChecked And IsNumeric(txtSeed.Text) And IsNumeric(txtIncrement.Text) Then + idYes = "YES" + TableBuilderGrid.AddItem KeyCol & vbTab & colname & vbTab & datatype & vbTab & collength & vbTab & nullability & vbTab & default & vbTab & idYes & vbTab & txtSeed.Text & vbTab & txtIncrement.Text + ElseIf chkIdent.Value = vbChecked And (IsNumeric(txtSeed.Text) = False Or IsNumeric(txtIncrement.Text) = False) Then + MsgBox "Not a valid seed or increment" + Exit Sub + Else + TableBuilderGrid.AddItem KeyCol & vbTab & colname & vbTab & datatype & vbTab & collength & vbTab & nullability & vbTab & default + End If + + + +End Sub + +Private Sub cbotables_Click() +Listcols cboServers.Text, cboDatabases.Text, cbotables.Text +End Sub +Private Sub cbotables2_Click() +Listcols2 cboServers.Text, cboDatabases.Text, cbotables2.Text +End Sub + +Private Sub cmdAddCol_Click() +Dim nullability As String +Dim KeyCol As String +Select Case chkNull.Value + +Case 1 +nullability = "NULL" +Case 0 +nullability = "NOT NULL" +End Select + +If optKey.Value = True Then + KeyCol = "PK" +End If + + + +AddColToGrid KeyCol, txtcolname.Text, lstDatatypes.Text, txtLength.Text, nullability, txtdefault.Text + +txtcolname.Text = "" +txtLength.Text = "" +chkNull.Value = 0 +optKey.Value = False +txtdefault.Text = "" +End Sub + +Private Sub cmdAddrelgrid_Click() +AddFieldsToGrid lstcol1.Text, lstcol2.Text +End Sub + +Private Sub AddRelationshipToTable(servername As String, databasename As String, reffingTable As String, reffedTable As String) +Dim dmo_server As SQLDMO.SQLServer +Dim dmo_user As SQLDMO.User +Dim oKey As SQLDMO.Key +Dim i As Integer + +Set dmo_server = New SQLDMO.SQLServer + +dmo_server.LoginSecure = True +dmo_server.Connect servername + +If relgrid.Rows > 0 Then + Set oKey = New SQLDMO.Key + oKey.Type = SQLDMOKey_Foreign + + 'we only need to set the referenced table name + 'as we will be adding the key to the referencing table + + oKey.ReferencedTable = reffedTable + + + For i = 0 To relgrid.Rows - 1 + oKey.KeyColumns.Add relgrid.TextMatrix(i, 2) + oKey.ReferencedColumns.Add relgrid.TextMatrix(i, 0) + Next i + + dmo_server.Databases(databasename).Tables(reffingTable).Keys.Add oKey +End If + + +End Sub + + +Private Sub cmdAddRelToDB_Click() +AddRelationshipToTable cboServers.Text, cboDatabases.Text, cbotables2.Text, cbotables.Text +relgrid.Clear +relgrid.Rows = 0 +End Sub + +Private Sub cmdClear_Click() +TableBuilderGrid.Clear +TableBuilderGrid.Rows = 0 +End Sub + +Private Sub cmdCreate_Click() +AddTableToDatabase cboServers.Text, cboDatabases.Text, txtTableName.Text +ListTables cboServers.Text, cboDatabases.Text +ListTables2 cboServers.Text, cboDatabases.Text +End Sub + + + + + + + +Private Sub AddTableToDatabase(servername As String, databasename As String, tablename As String) +On Error GoTo err_handler +Dim i As Integer 'for rows +Dim j As Integer 'for columns +Dim oSrv As SQLDMO.SQLServer +Dim oTable As SQLDMO.Table +Dim ocol As SQLDMO.Column +Dim colname As String +Dim datatype As String +Dim collength As Integer +Dim nullability As Boolean +Dim objPK As SQLDMO.Key +Dim objDefault As SQLDMO.default + +Set objPK = New SQLDMO.Key + +Set oSrv = New SQLDMO.SQLServer + +oSrv.LoginSecure = True +oSrv.Connect servername + +Set oTable = New SQLDMO.Table +oTable.Name = tablename + + +'loop through the rows of the grid +For i = 0 To TableBuilderGrid.Rows - 1 +'initialise a new column every time we go to a new row + Set ocol = New SQLDMO.Column +'is it a textual column that will require a length ? + If TableBuilderGrid.TextMatrix(i, 2) = "char" Or TableBuilderGrid.TextMatrix(i, 2) = "varchar" Or TableBuilderGrid.TextMatrix(i, 2) = "nvarchar" Or TableBuilderGrid.TextMatrix(i, 2) = "nchar" Then + ocol.Name = TableBuilderGrid.TextMatrix(i, 1) + ocol.datatype = TableBuilderGrid.TextMatrix(i, 2) + ocol.Length = CStr(TableBuilderGrid.TextMatrix(i, 3)) + If TableBuilderGrid.TextMatrix(i, 4) = "NOT NULL" Then + ocol.AllowNulls = False + Else + ocol.AllowNulls = True + End If + Else + ocol.Name = TableBuilderGrid.TextMatrix(i, 1) + ocol.datatype = TableBuilderGrid.TextMatrix(i, 2) + If TableBuilderGrid.TextMatrix(i, 4) = "NOT NULL" Then + ocol.AllowNulls = False + Else + ocol.AllowNulls = True + End If + End If + + If TableBuilderGrid.TextMatrix(i, 6) = "YES" Then + ocol.Identity = True + ocol.IdentitySeed = TableBuilderGrid.TextMatrix(i, 7) + ocol.IdentityIncrement = TableBuilderGrid.TextMatrix(i, 8) + End If + + oTable.Columns.Add ocol + +Next i + +oSrv.Databases(databasename).Tables.Add oTable + +'Now for Primary Keys and defaults + +'Primary Keys +Set objPK = New SQLDMO.Key +For i = 0 To TableBuilderGrid.Rows - 1 + If TableBuilderGrid.TextMatrix(i, 0) = "PK" Then + objPK.KeyColumns.Add TableBuilderGrid.TextMatrix(i, 1) + End If +Next i + +If objPK.KeyColumns.Count > 0 Then + +objPK.Name = "My_PK_" & CStr(Minute(Now())) & "_" & CStr(Second(Now())) + + +objPK.FillFactor = 85 +objPK.Type = SQLDMOKey_Primary + +oSrv.Databases(databasename).Tables(tablename).Keys.Add objPK + +End If + + +'Defaults +For i = 0 To TableBuilderGrid.Rows - 1 + Set objDefault = New SQLDMO.default + objDefault.Name = "DEFAULT_" & TableBuilderGrid.TextMatrix(i, 1) + If TableBuilderGrid.TextMatrix(i, 5) <> "" Then + oSrv.Databases(databasename).Tables(tablename).BeginAlter + oSrv.Databases(databasename).Tables(tablename).Columns(TableBuilderGrid.TextMatrix(i, 1)).DRIDefault.Text = "'" & TableBuilderGrid.TextMatrix(i, 5) & "'" + oSrv.Databases(databasename).Tables(tablename).DoAlter + End If + Next i + +TableBuilderGrid.Rows = 0 + +Exit Sub + +err_handler: + +MsgBox Err.Description, vbInformation, "Mistake made" +Exit Sub + +End Sub +Private Sub ListDataBases(servername As String) +Dim dmoSrv As SQLDMO.SQLServer +Dim dmoDB As SQLDMO.database + +Set dmoSrv = New SQLDMO.SQLServer +cboDatabases.Clear +dmoSrv.LoginSecure = True +dmoSrv.Connect servername + +For Each dmoDB In dmoSrv.Databases + cboDatabases.AddItem dmoDB.Name +Next dmoDB +End Sub + + + +Private Sub ListTables(servername As String, databasename As String) +Dim dmoSrv As SQLDMO.SQLServer +Dim dmoDB As SQLDMO.database +Dim oTable As SQLDMO.Table + +Set dmoSrv = New SQLDMO.SQLServer +cbotables.Clear +dmoSrv.LoginSecure = True +dmoSrv.Connect servername + +For Each oTable In dmoSrv.Databases(databasename).Tables + If oTable.SystemObject = False Then + cbotables.AddItem oTable.Name + End If +Next oTable +End Sub +Private Sub ListTables2(servername As String, databasename As String) +Dim dmoSrv As SQLDMO.SQLServer +Dim dmoDB As SQLDMO.database +Dim oTable As SQLDMO.Table + +Set dmoSrv = New SQLDMO.SQLServer +cbotables2.Clear +dmoSrv.LoginSecure = True +dmoSrv.Connect servername + +For Each oTable In dmoSrv.Databases(databasename).Tables + If oTable.SystemObject = False Then + cbotables2.AddItem oTable.Name + End If +Next oTable +End Sub + +Private Sub Listcols2(servername As String, databasename As String, tablename As String) +Dim dmoSrv As SQLDMO.SQLServer +Dim ocol As SQLDMO.Column + +Set dmoSrv = New SQLDMO.SQLServer +lstcol2.Clear +dmoSrv.LoginSecure = True +dmoSrv.Connect servername + +For Each ocol In dmoSrv.Databases(databasename).Tables(tablename).Columns + lstcol2.AddItem ocol.Name +Next ocol +End Sub +Private Sub Listcols(servername As String, databasename As String, tablename As String) +Dim dmoSrv As SQLDMO.SQLServer +Dim ocol As SQLDMO.Column + +Set dmoSrv = New SQLDMO.SQLServer +lstcol1.Clear +dmoSrv.LoginSecure = True +dmoSrv.Connect servername + +For Each ocol In dmoSrv.Databases(databasename).Tables(tablename).Columns + lstcol1.AddItem ocol.Name +Next ocol +End Sub + + + +Private Sub ListDataTypes(servername As String) +Dim dt As SQLDMO.SystemDatatype +Dim dts As SQLDMO.SystemDatatypes +Dim dmoSrv As SQLDMO.SQLServer +lstDatatypes.Clear + +Set dmoSrv = New SQLDMO.SQLServer + +dmoSrv.LoginSecure = True +dmoSrv.Connect servername + +For Each dt In dmoSrv.Databases("master").SystemDatatypes + lstDatatypes.AddItem dt.Name +Next dt +End Sub +Private Sub AddFieldsToGrid(leftCol As String, rightcol As String) + +relgrid.AddItem leftCol & vbTab & "-->" & vbTab & rightcol + +End Sub + +Private Sub CreateRelationship(serverame As String, databasename As String, tablename As String) + +Dim dmoSrv As SQLDMO.SQLServer + +Set dmoSrv = New SQLDMO.SQLServer + +dmoSrv.LoginSecure = True +dmoSrv.Connect servername + + + + +End Sub + + +Private Sub listServers() + +Dim oServer As SQLDMO.SQLServer +Dim oApp As New SQLDMO.Application +Dim oServerGroup As SQLDMO.ServerGroup +Dim oRegisteredServer As SQLDMO.RegisteredServer + +cboServers.Clear + + Set oServer = New SQLDMO.SQLServer + +For Each oRegisteredServer In oApp.ServerGroups(1).RegisteredServers + cboServers.AddItem oRegisteredServer.Name +Next oRegisteredServer + End Sub + + +Private Sub Form_Load() +TableBuilderGrid.Rows = 0 +relgrid.Rows = 0 +relgrid.ColWidth(0) = 2500 +relgrid.ColWidth(1) = 500 +relgrid.ColWidth(2) = 2500 +listServers +End Sub + + + + + diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/15 minute Checker/MSSCCPRJ.SCC b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/15 minute Checker/MSSCCPRJ.SCC new file mode 100644 index 0000000..1d6a7fa --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/15 minute Checker/MSSCCPRJ.SCC @@ -0,0 +1,5 @@ +[SCC] +SCC=This is a source code control file +[Project1.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/15 minute Checker/Module1.bas b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/15 minute Checker/Module1.bas new file mode 100644 index 0000000..173cd64 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/15 minute Checker/Module1.bas @@ -0,0 +1,61 @@ +Attribute VB_Name = "Module1" +Option Explicit +Sub main() +ListNewDatabases 15 +End Sub + + +Private Sub ListNewDatabases(MinsAgo As Integer) +Dim oServer As SQLDMO.SQLServer +Dim oBackup As SQLDMO.Backup +Dim oDatabase As SQLDMO.Database +Dim oList As SQLDMO.SQLObjectList +Dim obj As Object +Dim oUsr As SQLDMO.User +Dim oJob As SQLDMO.Job +Dim OutputString As String +Dim oObj As Object + +On Error GoTo err_handler + +Set oServer = New SQLDMO.SQLServer +Set oBackup = New SQLDMO.Backup + + + oServer.LoginSecure = True + oServer.Connect "AM2" + + For Each oDatabase In oServer.Databases + If oDatabase.Name <> "master" And oDatabase.Name <> "tempdb" And oDatabase.Name <> "model" And oDatabase.Name <> "msdb" Then + 'Check for created databases + If DateDiff("n", Left(oDatabase.CreateDate, 19), Format(Now(), "dd-mm-yyyy hh:mm:ss")) <= MinsAgo Then + OutputString = OutputString & "Database " & oDatabase.Name & " on " & oServer.Name & " was created on " & Left(oDatabase.CreateDate, 19) & " by " & oDatabase.Owner & vbCrLf & "The database was backed Up to \\MyNetworkServer\FullBackupShare\" & oServer.Name & "\" & oDatabase.Name & "_" & Format(Now(), "yyyymmyy") & ".bak" & vbCrLf + oBackup.Database = oDatabase.Name + oBackup.Files = "f:\DBBackups\" & oServer.Name & "\" & oDatabase.Name & "_" & Format(Now(), "yyyymmyy") & ".bak" + oBackup.SQLBackup oServer + End If + + End If + Next oDatabase + + oServer.DisConnect + + + +If OutputString <> "" Then + +Open "c:\NewDBs.txt" For Output As #1 + +Print #1, OutputString + +End If + + + +Exit Sub +Close #1 + +err_handler: +Resume Next + +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/15 minute Checker/Project1.vbp b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/15 minute Checker/Project1.vbp new file mode 100644 index 0000000..a3a86d8 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/15 minute Checker/Project1.vbp @@ -0,0 +1,33 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\stdole2.tlb#OLE Automation +Reference=*\G{10010001-E260-11CF-AE68-00AA004A34D5}#8.0#0#C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll#Microsoft SQLDMO Object Library +Module=Module1; Module1.bas +Startup="Sub Main" +Command32="" +Name="Project1" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionCompanyName="Allison Mitchell" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/15 minute Checker/Project1.vbw b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/15 minute Checker/Project1.vbw new file mode 100644 index 0000000..3740a92 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/15 minute Checker/Project1.vbw @@ -0,0 +1 @@ +Module1 = 62, 105, 1180, 891, diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/Form1.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/Form1.frm new file mode 100644 index 0000000..9ac6c2f --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/Form1.frm @@ -0,0 +1,443 @@ +VERSION 5.00 +Begin VB.Form Form1 + Caption = "Backup" + ClientHeight = 9495 + ClientLeft = 5190 + ClientTop = 2430 + ClientWidth = 7770 + LinkTopic = "Form1" + ScaleHeight = 9495 + ScaleWidth = 7770 + Begin VB.TextBox Text1 + Appearance = 0 'Flat + BackColor = &H8000000F& + BorderStyle = 0 'None + BeginProperty Font + Name = "Courier New" + Size = 36 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 5355 + Left = 6480 + MultiLine = -1 'True + TabIndex = 19 + Text = "Form1.frx":0000 + Top = 330 + Width = 645 + End + Begin VB.CommandButton cmdremove + Caption = "Remove" + Height = 405 + Left = 3450 + TabIndex = 18 + Top = 4530 + Width = 1695 + End + Begin VB.CommandButton cmdAdd + Caption = "Add" + Height = 405 + Left = 3450 + TabIndex = 17 + Top = 3990 + Width = 1695 + End + Begin VB.ComboBox cboRetain + Height = 315 + ItemData = "Form1.frx":000A + Left = 420 + List = "Form1.frx":002C + TabIndex = 15 + Top = 7200 + Width = 525 + End + Begin VB.CommandButton cmdCreate + Caption = "Create" + BeginProperty Font + Name = "MS Sans Serif" + Size = 18 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 1395 + Left = 3570 + TabIndex = 14 + Top = 7740 + Width = 3465 + End + Begin VB.OptionButton OptLog + Caption = "LOG" + Height = 285 + Left = 3630 + TabIndex = 13 + Top = 6570 + Width = 675 + End + Begin VB.OptionButton OptDiff + Caption = "DIFFERENTIAL" + Height = 345 + Left = 3630 + TabIndex = 12 + Top = 6000 + Width = 1455 + End + Begin VB.OptionButton optFull + Caption = "FULL" + Height = 285 + Left = 3630 + TabIndex = 11 + Top = 5520 + Width = 825 + End + Begin VB.ComboBox cboDatabases + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 360 + Left = 360 + TabIndex = 4 + Top = 2220 + Width = 4755 + End + Begin VB.TextBox txtName + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 315 + Left = 360 + TabIndex = 3 + Top = 3060 + Width = 4755 + End + Begin VB.Frame frINIT + Caption = "Backup Types" + Height = 1065 + Left = 360 + TabIndex = 2 + Top = 5580 + Width = 2535 + Begin VB.OptionButton OptOverwrite + Caption = "Overwrite" + Height = 225 + Left = 270 + TabIndex = 10 + Top = 690 + Width = 1485 + End + Begin VB.OptionButton optAppend + Caption = "Append" + Height = 255 + Left = 270 + TabIndex = 9 + Top = 300 + Width = 1545 + End + End + Begin VB.ListBox lstdevices + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 1020 + Left = 360 + TabIndex = 1 + Top = 3990 + Width = 2895 + End + Begin VB.ComboBox cboServers + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 360 + Left = 360 + TabIndex = 0 + Top = 1050 + Width = 4755 + End + Begin VB.Label Label5 + Caption = "Retain Days" + Height = 195 + Left = 390 + TabIndex = 16 + Top = 6990 + Width = 1425 + End + Begin VB.Label Label4 + Caption = "Name for the backup" + Height = 255 + Left = 360 + TabIndex = 8 + Top = 2820 + Width = 1905 + End + Begin VB.Label Label3 + Caption = "Devices" + Height = 255 + Left = 360 + TabIndex = 7 + Top = 3720 + Width = 2205 + End + Begin VB.Label Label2 + Caption = "Databases" + Height = 285 + Left = 360 + TabIndex = 6 + Top = 1980 + Width = 2415 + End + Begin VB.Label Label1 + Caption = "Servers" + Height = 315 + Left = 360 + TabIndex = 5 + Top = 810 + Width = 2115 + End +End +Attribute VB_Name = "Form1" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit +Public oServer As SQLDMO.SQLServer +Public oDevice As SQLDMO.BackupDevice +Public oDatabase As SQLDMO.Database +Public oBackup As SQLDMO.Backup +Public oRegisteredServer As SQLDMO.RegisteredServer +Public oApp As SQLDMO.Application +Public oGroup As SQLDMO.ServerGroup +Public oRestore As SQLDMO.Restore + + +Private Sub ShowServers() + +Set oApp = New SQLDMO.Application +Set oRegisteredServer = New SQLDMO.RegisteredServer + +cboServers.Clear + +For Each oGroup In oApp.ServerGroups + +For Each oRegisteredServer In oApp.ServerGroups(oGroup.Name).RegisteredServers + cboServers.AddItem oRegisteredServer.Name +Next oRegisteredServer + +Next oGroup + +Set oGroup = Nothing +Set oRegisteredServer = Nothing +Set oApp = Nothing + +End Sub + +Private Sub ShowDatabases(servername As String) + +Set oServer = New SQLDMO.SQLServer + +oServer.LoginSecure = True +oServer.Connect servername + +cboDatabases.Clear + +For Each oDatabase In oServer.Databases + cboDatabases.AddItem oDatabase.Name +Next oDatabase + + +oServer.DisConnect +Set oServer = Nothing +Set oDatabase = Nothing + + +End Sub + +Private Sub ShowBackupDevices(servername As String) + +Set oServer = New SQLDMO.SQLServer + +oServer.LoginSecure = True +oServer.Connect servername + +lstdevices.Clear + +For Each oDevice In oServer.BackupDevices + lstdevices.AddItem oDevice.Name +Next oDevice + +oServer.DisConnect +Set oServer = Nothing +Set oDevice = Nothing + +End Sub + +Private Sub BackupTheDatabase(servername As String, DatabaseName As String, Location As String, DeviceYN As Integer, BackupType As SQLDMO_BACKUP_TYPE, RetainDays As Integer, InitFirst As Boolean, BackupName As String) +On Error GoTo Err_handler + +Set oServer = New SQLDMO.SQLServer +Set oBackup = New SQLDMO.Backup +Set oRestore = New SQLDMO.Restore + +oServer.LoginSecure = True +oServer.Connect servername + +oBackup.Action = BackupType +oBackup.BackupSetName = BackupName +oBackup.Database = DatabaseName +oBackup.RetainDays = RetainDays +oBackup.Initialize = InitFirst + + + + +If DeviceYN = 1 Then + oBackup.Devices = Location + oRestore.Devices = Location +Else + oBackup.Files = Location + oRestore.Files = Location +End If + + + +oBackup.SQLBackup oServer +oRestore.SQLVerify oServer + +MsgBox "The database Backup Succeeded", vbOKOnly, "Backup Completed" + +oServer.DisConnect +Set oServer = Nothing +Exit Sub + + +Err_handler: + +If Err.Number = -2147218262 Then + MsgBox "The backup you have just performed would appear to be corrupted", vbCritical, "Backup problem" +Else + MsgBox "The database Backup Failed" & vbCrLf & Err.Description, vbOKOnly, "Backup Completed" +End If + +oServer.DisConnect +Set oServer = Nothing +Exit Sub + +End Sub + +Private Sub cboServers_Click() +ShowDatabases cboServers.Text +ShowBackupDevices cboServers.Text +End Sub + +Private Sub cmdAdd_Click() +Dim strNewLocation As String + +strNewLocation = InputBox("Enter A New Location", "New Backup Location") + +If strNewLocation <> "" Then + lstdevices.AddItem strNewLocation +End If + + +End Sub + +Private Sub cmdCreate_Click() + +Dim servername As String +Dim BackupType As SQLDMO_BACKUP_TYPE +Dim Init As Boolean +Dim DeviceCounter As Integer +Dim BackupName As String + + + + +Init = False + +If optFull.Value = True Then + BackupType = SQLDMOBackup_Database +ElseIf OptDiff.Value = True Then + BackupType = SQLDMOBackup_Differential +ElseIf OptLog.Value = True Then + BackupType = SQLDMOBackup_Log +End If + +If OptOverwrite.Value = True Then + Init = True +End If + + +If (cboServers.Text <> "" Or cboDatabases.Text <> "" Or lstdevices.ListIndex <> -1) Then + + Set oServer = New SQLDMO.SQLServer +Set oBackup = New SQLDMO.Backup + + +oServer.LoginSecure = True +oServer.Connect cboServers.Text + + + For Each oDevice In oServer.BackupDevices + If oDevice.Name = lstdevices.Text Then + DeviceCounter = 1 + End If + Next oDevice + + If txtName = "" Then + BackupName = cboDatabases.Text & "_" & Format(Now(), "yyyymmdd") & Format(Now(), "hhmmss") + Else + BackupName = txtName.Text + End If + + +BackupTheDatabase cboServers.Text, cboDatabases.Text, lstdevices.Text, DeviceCounter, BackupType, cboRetain.Text, Init, BackupName + + + +End If + + +End Sub + +Private Sub cmdremove_Click() +If lstdevices.ListIndex <> -1 Then + lstdevices.RemoveItem lstdevices.ListIndex +End If +End Sub + +Private Sub Form_Load() +cboRetain.ListIndex = 0 +ShowServers +optAppend.Value = True +optFull.Value = True +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/Form1.frx b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/Form1.frx new file mode 100644 index 0000000..870ec06 Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/Form1.frx differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/MSSCCPRJ.SCC b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/MSSCCPRJ.SCC new file mode 100644 index 0000000..1d6a7fa --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/MSSCCPRJ.SCC @@ -0,0 +1,5 @@ +[SCC] +SCC=This is a source code control file +[Project1.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/Project1.vbp b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/Project1.vbp new file mode 100644 index 0000000..6637186 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/Project1.vbp @@ -0,0 +1,33 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\stdole2.tlb#OLE Automation +Reference=*\G{10010001-E260-11CF-AE68-00AA004A34D5}#8.0#0#C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll#Microsoft SQLDMO Object Library +Form=Form1.frm +Startup="Form1" +Command32="" +Name="Project1" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionCompanyName="Allison Mitchell" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/Project1.vbw b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/Project1.vbw new file mode 100644 index 0000000..5cd67a8 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Backing up the database/Project1.vbw @@ -0,0 +1 @@ +Form1 = 13, 105, 1268, 868, C, 0, 0, 0, 0, C diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Create Backup Device/MSSCCPRJ.SCC b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Create Backup Device/MSSCCPRJ.SCC new file mode 100644 index 0000000..1d6a7fa --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Create Backup Device/MSSCCPRJ.SCC @@ -0,0 +1,5 @@ +[SCC] +SCC=This is a source code control file +[Project1.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Create Backup Device/Project1.vbp b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Create Backup Device/Project1.vbp new file mode 100644 index 0000000..19b889d --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Create Backup Device/Project1.vbp @@ -0,0 +1,33 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\stdole2.tlb#OLE Automation +Reference=*\G{10010001-E260-11CF-AE68-00AA004A34D5}#8.0#0#C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll#Microsoft SQLDMO Object Library +Form=frmCreateDevice.frm +Startup="frmCreateDevice" +Command32="" +Name="Project1" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionCompanyName="Allison Mitchell" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Create Backup Device/Project1.vbw b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Create Backup Device/Project1.vbw new file mode 100644 index 0000000..ff0c195 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Create Backup Device/Project1.vbw @@ -0,0 +1 @@ +frmCreateDevice = 173, 212, 1024, 788, , 0, 0, 0, 0, C diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Create Backup Device/frmCreateDevice.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Create Backup Device/frmCreateDevice.frm new file mode 100644 index 0000000..e5c71cc --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Create Backup Device/frmCreateDevice.frm @@ -0,0 +1,50 @@ +VERSION 5.00 +Begin VB.Form frmCreateDevice + Caption = "Form1" + ClientHeight = 1140 + ClientLeft = 6090 + ClientTop = 5835 + ClientWidth = 4215 + LinkTopic = "Form1" + ScaleHeight = 1140 + ScaleWidth = 4215 + Begin VB.CommandButton cmdCreate + Caption = "Create device" + Height = 585 + Left = 870 + TabIndex = 0 + Top = 180 + Width = 2535 + End +End +Attribute VB_Name = "frmCreateDevice" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmdCreate_Click() +Dim oServer As SQLDMO.SQLServer +Dim oDevice As SQLDMO.BackupDevice + +Set oServer = New SQLDMO.SQLServer + +oServer.LoginSecure = True +oServer.Connect "AM2" + +Set oDevice = New SQLDMO.BackupDevice + +oDevice.Name = "My_Backup_Device" +oDevice.Type = SQLDMODevice_DiskDump +oDevice.PhysicalLocation = "f:\DBBackups\MyBackups.bak" + +oServer.BackupDevices.Add oDevice + + +oServer.DisConnect + +Set oServer = Nothing + + +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Form1.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Form1.frm new file mode 100644 index 0000000..41a9f28 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Form1.frm @@ -0,0 +1,864 @@ +VERSION 5.00 +Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX" +Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "tabctl32.ocx" +Begin VB.Form Form1 + Caption = "Restore" + ClientHeight = 9420 + ClientLeft = 5610 + ClientTop = 2715 + ClientWidth = 10740 + LinkTopic = "Form1" + ScaleHeight = 9420 + ScaleWidth = 10740 + Begin TabDlg.SSTab SSTab1 + Height = 9465 + Left = 0 + TabIndex = 0 + Top = 0 + Width = 10755 + _ExtentX = 18971 + _ExtentY = 16695 + _Version = 393216 + TabHeight = 520 + TabCaption(0) = "General" + TabPicture(0) = "Form1.frx":0000 + Tab(0).ControlEnabled= -1 'True + Tab(0).Control(0)= "Label4" + Tab(0).Control(0).Enabled= 0 'False + Tab(0).Control(1)= "Label1" + Tab(0).Control(1).Enabled= 0 'False + Tab(0).Control(2)= "Label3" + Tab(0).Control(2).Enabled= 0 'False + Tab(0).Control(3)= "Label2" + Tab(0).Control(3).Enabled= 0 'False + Tab(0).Control(4)= "msf_Available" + Tab(0).Control(4).Enabled= 0 'False + Tab(0).Control(5)= "cboServers" + Tab(0).Control(5).Enabled= 0 'False + Tab(0).Control(6)= "cboDatabases" + Tab(0).Control(6).Enabled= 0 'False + Tab(0).Control(7)= "lstdevices" + Tab(0).Control(7).Enabled= 0 'False + Tab(0).Control(8)= "Text1" + Tab(0).Control(8).Enabled= 0 'False + Tab(0).Control(9)= "cmdChooseDeviceFile" + Tab(0).Control(9).Enabled= 0 'False + Tab(0).Control(10)= "Frame2" + Tab(0).Control(10).Enabled= 0 'False + Tab(0).Control(11)= "cmdRDDL(0)" + Tab(0).Control(11).Enabled= 0 'False + Tab(0).Control(12)= "cmdRDDL(1)" + Tab(0).Control(12).Enabled= 0 'False + Tab(0).ControlCount= 13 + TabCaption(1) = "Options" + TabPicture(1) = "Form1.frx":001C + Tab(1).ControlEnabled= 0 'False + Tab(1).Control(0)= "chkForce" + Tab(1).Control(1)= "msf_FileList" + Tab(1).Control(2)= "Frame1" + Tab(1).Control(3)= "Label6" + Tab(1).ControlCount= 4 + TabCaption(2) = "DDL" + TabPicture(2) = "Form1.frx":0038 + Tab(2).ControlEnabled= 0 'False + Tab(2).Control(0)= "txtDDL" + Tab(2).Control(1)= "Label7" + Tab(2).ControlCount= 2 + Begin VB.CommandButton cmdRDDL + Caption = "Restore" + Height = 855 + Index = 1 + Left = 8490 + TabIndex = 26 + Top = 8430 + Width = 1695 + End + Begin VB.CommandButton cmdRDDL + Caption = "Generate" + Height = 855 + Index = 0 + Left = 6690 + TabIndex = 25 + Top = 8430 + Width = 1695 + End + Begin VB.TextBox txtDDL + BeginProperty Font + Name = "Comic Sans MS" + Size = 14.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H000000FF& + Height = 6945 + Left = -74520 + MultiLine = -1 'True + TabIndex = 23 + Top = 1530 + Width = 9765 + End + Begin VB.Frame Frame2 + Caption = "Type Of Restore" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 675 + Left = 2280 + TabIndex = 20 + Top = 4560 + Width = 4845 + Begin VB.OptionButton optLog + Caption = "Log" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 1740 + TabIndex = 22 + Top = 330 + Width = 2625 + End + Begin VB.OptionButton optDatabase + Caption = "Database" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 195 + Left = 150 + TabIndex = 21 + Top = 330 + Width = 1335 + End + End + Begin VB.CheckBox chkForce + Caption = "Force restore Over Existing Database" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 285 + Left = -73710 + TabIndex = 19 + Top = 1140 + Width = 3915 + End + Begin VB.CommandButton cmdChooseDeviceFile + Caption = "..." + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 1485 + Left = 9630 + TabIndex = 18 + Top = 2670 + Width = 315 + End + Begin MSFlexGridLib.MSFlexGrid msf_FileList + Height = 2325 + Left = -73830 + TabIndex = 16 + Top = 2190 + Width = 8025 + _ExtentX = 14155 + _ExtentY = 4101 + _Version = 393216 + FixedCols = 0 + AllowUserResizing= 3 + End + Begin VB.TextBox Text1 + BackColor = &H80000000& + BorderStyle = 0 'None + BeginProperty Font + Name = "Courier New" + Size = 48 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 8295 + Left = 270 + MultiLine = -1 'True + TabIndex = 15 + Text = "Form1.frx":0054 + Top = 720 + Width = 705 + End + Begin VB.Frame Frame1 + Caption = "Recovery State options" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 2715 + Left = -73770 + TabIndex = 9 + Top = 5700 + Width = 8085 + Begin VB.OptionButton optrecover + Caption = "Recover the Database to operational State" + Height = 375 + Left = 240 + TabIndex = 13 + Top = 420 + Width = 6105 + End + Begin VB.OptionButton optNonop + Caption = "Do not recover the database but able to apply more log backups" + Height = 375 + Left = 210 + TabIndex = 12 + Top = 1080 + Width = 6045 + End + Begin VB.OptionButton optStandby + Caption = "Do not recover the database but leave it as Read Only and able to apply more log backups" + Height = 375 + Left = 210 + TabIndex = 11 + Top = 1680 + Width = 6855 + End + Begin VB.TextBox txtStandby + Height = 285 + Left = 1830 + TabIndex = 10 + Top = 2250 + Width = 4635 + End + Begin VB.Label Label5 + Caption = "Standby File" + Height = 255 + Left = 750 + TabIndex = 14 + Top = 2250 + Width = 945 + End + End + Begin VB.ListBox lstdevices + Height = 1425 + Left = 2280 + TabIndex = 6 + Top = 2700 + Width = 7275 + End + Begin VB.ComboBox cboDatabases + Height = 315 + Left = 4350 + TabIndex = 2 + Top = 1620 + Width = 5925 + End + Begin VB.ComboBox cboServers + Height = 315 + Left = 4380 + TabIndex = 1 + Top = 1110 + Width = 5895 + End + Begin MSFlexGridLib.MSFlexGrid msf_Available + Height = 1665 + Left = 2250 + TabIndex = 5 + Top = 5670 + Width = 8055 + _ExtentX = 14208 + _ExtentY = 2937 + _Version = 393216 + Cols = 4 + FixedCols = 0 + AllowUserResizing= 3 + End + Begin VB.Label Label7 + Caption = "Generated DDL" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 375 + Left = -74520 + TabIndex = 24 + Top = 1170 + Width = 6285 + End + Begin VB.Label Label6 + Caption = "Restore Database Files As:" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 225 + Left = -73740 + TabIndex = 17 + Top = 1890 + Width = 5355 + End + Begin VB.Label Label2 + Caption = "Backup Location Or Device" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 315 + Left = 2190 + TabIndex = 8 + Top = 2460 + Width = 2955 + End + Begin VB.Label Label3 + Caption = "Available Backups" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 2190 + TabIndex = 7 + Top = 5460 + Width = 3555 + End + Begin VB.Label Label1 + Caption = "Restore As Database:" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 195 + Left = 2190 + TabIndex = 4 + Top = 1680 + Width = 2205 + End + Begin VB.Label Label4 + Caption = "Server" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 195 + Left = 2160 + TabIndex = 3 + Top = 1200 + Width = 2175 + End + End +End +Attribute VB_Name = "Form1" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + + +Private Sub GenerateDDLAndRestore(servername As String, DatabaseName As String, Force As Integer, location As String, deviceYN As Integer, DBRestore As Integer, filenumber As Integer, LeftInState As Integer, MoveFiles As Integer, movestring As String, standbyfilesloc As String) + +On Error GoTo err_handler + +Set oRestore = New SQLDMO.Restore + + +'check to see if using Device or file +If deviceYN = 1 Then + oRestore.Devices = location +Else + oRestore.Files = location +End If + +'Should we force this backup over the top of the existing Database + +If Force = 1 Then + oRestore.ReplaceDatabase = True +End If + +'What type of backup are we doing + +If DBRestore = 1 Then + oRestore.Action = SQLDMORestore_Database +Else + oRestore.Action = SQLDMORestore_Log +End If + +'Are we moving the files at all + +If MoveFiles = 1 Then + oRestore.RelocateFiles = movestring +End If + +'What database do we want to restore +oRestore.Database = DatabaseName + +Select Case LeftInState + +'Recover the database +Case 1 +oRestore.LastRestore = True +'Leave non-operational +Case 2 +oRestore.LastRestore = False +'leave in standby +Case 3 +oRestore.LastRestore = False +oRestore.StandbyFiles = standbyfilesloc + +End Select + +oRestore.filenumber = filenumber + +'Because we want to reuse this procedure for DDL only or DDl and +'actual restore we include this clause here. +If servername <> "" Then + Set oServer = New SQLDMO.SQLServer + oServer.LoginSecure = True + oServer.Connect servername + + oRestore.SQLRestore oServer +End If + + +txtDDL.Text = oRestore.GenerateSQL + +Exit Sub + +err_handler: +MsgBox "The restore has failed because... " & vbCrLf & Err.Description +Exit Sub + + + + + + +End Sub + + +Private Sub cboServers_Click() + +'Show the databases on the server selected +ShowDatabases cboServers.Text +End Sub + +Private Sub cmdChooseDeviceFile_Click() +Form2.Visible = True +End Sub + + + + +Private Sub cmdRDDL_Click(Index As Integer) + + + +If cboServers.Text <> "" And cboDatabases.Text <> "" And lstdevices.Text <> "" And msf_Available.Rows > 1 Then + +Set oServer = New SQLDMO.SQLServer +Set oRestore = New SQLDMO.Restore + +oServer.LoginSecure = True +oServer.Connect cboServers.Text + + + +Dim iLeftInState As Integer +Dim iDBRestore As Integer +Dim iForce As Integer +Dim ideviceYN As Integer +Dim iMoveFiles As Integer +Dim iBackupType As Integer +Dim strMoveFiles As String +Dim qry_Comparison As SQLDMO.QueryResults +Dim i As Integer + +iForce = 0 +ideviceYN = 0 +iBackupType = 1 +strMoveFiles = "" +iMoveFiles = 0 + + +Select Case chkForce.Value + +Case vbChecked +iForce = 1 +End Select + +For Each oDevice In oServer.BackupDevices + If oDevice.Name = lstdevices.Text Then + ideviceYN = 1 + End If +Next oDevice + + +Select Case optDatabase.Value + +Case False +iBackupType = 0 +End Select + + +If optrecover.Value = True Then + iLeftInState = 1 +ElseIf optNonop.Value = True Then + iLeftInState = 2 +ElseIf optStandby = True Then + iLeftInState = 3 +End If + +If iLeftInState = 3 And txtStandby = "" Then + MsgBox "You have chosen to place the database in standby." & vbCrLf & "You need to specify an undo file", vbInformation, "Missing Undo File" + Exit Sub +End If + +'Now the tricky part. We need to compare the values for the placement of the +'files in the grid with those that we know are in the backupset row for row. +'If we find any that are different then this will need to be our +'move string for the restore + +If ideviceYN = 1 Then + oRestore.Devices = lstdevices.Text +Else + oRestore.Files = lstdevices.Text +End If + +oRestore.filenumber = msf_Available.TextMatrix(msf_Available.Row, 1) + +Set qry_Comparison = oRestore.ReadFileList(oServer) + +For i = 1 To qry_Comparison.Rows + If msf_FileList.TextMatrix(i, 1) <> qry_Comparison.GetColumnString(i, 2) Then + strMoveFiles = strMoveFiles & "[" & msf_FileList.TextMatrix(i, 0) & "],[" & msf_FileList.TextMatrix(i, 1) & "]," + End If +Next i + +If Len(strMoveFiles) > 0 Then + strMoveFiles = Mid(strMoveFiles, 1, Len(strMoveFiles) - 1) + iMoveFiles = 1 +End If + + +Select Case Index + +Case 0 'Generate DDL only +GenerateDDLAndRestore "", cboDatabases.Text, iForce, lstdevices.Text, ideviceYN, iBackupType, oRestore.filenumber, iLeftInState, iMoveFiles, strMoveFiles, txtStandby.Text + +Case 1 +GenerateDDLAndRestore "", cboDatabases.Text, iForce, lstdevices.Text, ideviceYN, iBackupType, oRestore.filenumber, iLeftInState, iMoveFiles, strMoveFiles, txtStandby.Text +GenerateDDLAndRestore cboServers.Text, cboDatabases.Text, iForce, lstdevices.Text, ideviceYN, iBackupType, oRestore.filenumber, iLeftInState, iMoveFiles, strMoveFiles, txtStandby.Text + + +End Select + +End If + + +End Sub + +Private Sub Form_Load() + +'Set the headings for our Flexgrid which is +'going to show any backups on the media + +msf_Available.TextMatrix(0, 0) = "Backup Type" +msf_Available.TextMatrix(0, 1) = "Position" +msf_Available.TextMatrix(0, 2) = "Database Name" +msf_Available.TextMatrix(0, 3) = "Backup Finish Date" +msf_FileList.TextMatrix(0, 0) = "Logical File Name" +msf_FileList.TextMatrix(0, 1) = "Physical File Name" + +'Set the widths of the cells to a decent first width +'these can be adjusted. This is on both the gris that +'will be used to display the results of the RESTORE HEADERONLY +'and the RESTORE FILELISTONLY + +msf_Available.ColWidth(0) = 1215 +msf_Available.ColWidth(1) = 735 +msf_Available.ColWidth(2) = 3255 +msf_Available.ColWidth(3) = 2685 +msf_FileList.ColWidth(0) = 3952 +msf_FileList.ColWidth(1) = 3953 + +'Make sure the first tab we show is the general tab + +SSTab1.Tab = 0 + +msf_FileList.Rows = 1 +msf_Available.Rows = 1 + +'Populate our servers combobox with the names of all our servers +ShowServers + +optDatabase.Value = True +optrecover.Value = True + + +End Sub + + + + +Private Sub ShowServers() + +Set oApp = New SQLDMO.Application +Set oRegisteredServer = New SQLDMO.RegisteredServer + +cboServers.Clear + +For Each oGroup In oApp.ServerGroups + +For Each oRegisteredServer In oApp.ServerGroups(oGroup.Name).RegisteredServers + cboServers.AddItem oRegisteredServer.Name +Next oRegisteredServer + +Next oGroup + +Set oGroup = Nothing +Set oRegisteredServer = Nothing +Set oApp = Nothing + +End Sub + + +Private Sub ShowDatabases(servername As String) + +Set oServer = New SQLDMO.SQLServer + +oServer.LoginSecure = True +oServer.Connect servername + +cboDatabases.Clear + +For Each oDatabase In oServer.Databases + cboDatabases.AddItem oDatabase.Name +Next oDatabase + + +oServer.DisConnect +Set oServer = Nothing +Set oDatabase = Nothing + + +End Sub + +Private Sub ShowContentsOfBackup(servername As String, devicename As String) + +Dim oHeader As SQLDMO.QueryResults +Dim DeviceCounter As Integer +Dim i As Integer +Dim Backup_type As String +DeviceCounter = 0 +msf_Available.Rows = 1 + +Set oServer = New SQLDMO.SQLServer +Set oRestore = New SQLDMO.Restore + + +oServer.LoginSecure = True +oServer.Connect servername + +'See if the name we passed is a device or an adhoc file + +For Each oDevice In oServer.BackupDevices + If oDevice.Name = devicename Then + DeviceCounter = 1 + End If +Next oDevice + + + +If DeviceCounter = 0 Then + oRestore.Files = devicename +Else + oRestore.Devices = devicename +End If + + +'here is where we read the contents of the backup header into a Queryresults Object +'ready for processing. A Queryresults object is very much like a table so we +' just go through it processing rows and columns. this is the RESTORE HEADERONLY part + +Set oHeader = oRestore.ReadBackupHeader(oServer) + +For i = 1 To oHeader.Rows + +'Here we convery the unintelligible integer value for backup type into +'something we can read and comprehend without opening the reference books + +Select Case oHeader.GetColumnString(i, 3) + Case 1 + Backup_type = "FULL" + Case 2 + Backup_type = "LOG" + Case 4 + Backup_type = "FILE" + Case 5 + Backup_type = "DIFF DB" + Case 6 + Backup_type = "DIFF FILE" +End Select + +'Add our required column and row values to the flexgrid showing us the contents +'of the backup device we specified + msf_Available.AddItem Backup_type & vbTab & oHeader.GetColumnString(i, 6) & vbTab & oHeader.GetColumnString(i, 10) & vbTab & oHeader.GetColumnString(i, 19) +Next i + +oServer.DisConnect +Set oServer = Nothing +Set oRestore = Nothing + + +End Sub + +Private Sub lstdevices_Click() + +'I don't want to see the devices if they are not linked to a server +If cboServers.Text <> "" Then + ShowContentsOfBackup cboServers.Text, lstdevices.Text +End If +End Sub + + +Private Sub ShowMeFileDetails(servername As String, devicename As String, filenumber As Integer) + + +Dim oFileResults As SQLDMO.QueryResults + +Dim DeviceCounter As Integer +Dim i As Integer + +DeviceCounter = 0 + +msf_FileList.Rows = 1 + +Set oServer = New SQLDMO.SQLServer +Set oRestore = New SQLDMO.Restore + + +oServer.LoginSecure = True +oServer.Connect servername + +'See if the name we passed is a device or an adhoc file + +For Each oDevice In oServer.BackupDevices + If oDevice.Name = devicename Then + DeviceCounter = 1 + End If +Next oDevice + + +If DeviceCounter = 0 Then + oRestore.Files = devicename +Else + oRestore.Devices = devicename +End If + +oRestore.filenumber = filenumber + + +'Up until now the code has been exactly the same as when +'we wanted to populate the other grid with details of our backup headers + +'this is the part that we do the equivalent of RESTORE FILELISTONLY + +Set oFileResults = oRestore.ReadFileList(oServer) + +For i = 1 To oFileResults.Rows + + +'Add our required column and row values to the flexgrid showing us the file details +'of the backup device we specified + msf_FileList.AddItem oFileResults.GetColumnString(i, 1) & vbTab & oFileResults.GetColumnString(i, 2) +Next i + +End Sub + +Private Sub msf_Available_Click() + +If msf_Available.Row <> 0 Then + ShowMeFileDetails cboServers.Text, lstdevices.Text, msf_Available.TextMatrix(msf_Available.Row, 1) +End If +End Sub + +Private Sub msf_FileList_Click() +Dim strNewFile As String +'Here we want to set any new values in the + +If msf_FileList.Col = 1 Then + strNewFile = InputBox("Enter New Location Of File", "New File Location", msf_FileList.Text) + If strNewFile = "" Or msf_FileList.Col <> 1 Then + msf_FileList.Text = msf_FileList.Text + Else + msf_FileList.Text = strNewFile + End If +End If + +End Sub + + diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Form1.frx b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Form1.frx new file mode 100644 index 0000000..c2b7f60 Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Form1.frx differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Form2.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Form2.frm new file mode 100644 index 0000000..5a23d1b --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Form2.frm @@ -0,0 +1,157 @@ +VERSION 5.00 +Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx" +Begin VB.Form Form2 + BackColor = &H00C0C0C0& + Caption = "Choose Location" + ClientHeight = 2370 + ClientLeft = 6090 + ClientTop = 5055 + ClientWidth = 6270 + LinkTopic = "Form2" + ScaleHeight = 2370 + ScaleWidth = 6270 + Begin MSComDlg.CommonDialog cdl1 + Left = 3060 + Top = 240 + _ExtentX = 847 + _ExtentY = 847 + _Version = 393216 + End + Begin VB.CommandButton cmdClose + Caption = "Close" + Height = 285 + Left = 4980 + TabIndex = 5 + Top = 1920 + Width = 1215 + End + Begin VB.OptionButton optFile + BackColor = &H00C0C0C0& + Caption = "File" + Height = 255 + Left = 240 + TabIndex = 4 + Top = 1110 + Width = 1845 + End + Begin VB.OptionButton optDevice + BackColor = &H00C0C0C0& + Caption = "Device" + Height = 225 + Left = 270 + TabIndex = 3 + Top = 420 + Width = 1695 + End + Begin VB.CommandButton cmdFind + Caption = "..." + Height = 375 + Left = 5640 + TabIndex = 2 + Top = 1380 + Width = 555 + End + Begin VB.TextBox txtFilename + Height = 315 + Left = 1230 + TabIndex = 1 + Top = 1380 + Width = 4335 + End + Begin VB.ComboBox cboDevices + Height = 315 + Left = 1260 + TabIndex = 0 + Top = 720 + Width = 4305 + End +End +Attribute VB_Name = "Form2" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + + +Private Sub ShowBackupDevices(servername As String) + +Set oServer = New SQLDMO.SQLServer + +oServer.LoginSecure = True +oServer.Connect servername + +cboDevices.Clear + +For Each oDevice In oServer.BackupDevices + cboDevices.AddItem oDevice.Name +Next oDevice + +oServer.DisConnect +Set oServer = Nothing +Set oDevice = Nothing + +End Sub + + +Private Sub cmdClose_Click() +If optDevice.Value = True And cboDevices.Text <> "" Then + Form1.lstdevices.AddItem cboDevices.Text +ElseIf optFile.Value = True And txtFilename.Text <> "" Then + Form1.lstdevices.AddItem txtFilename.Text +End If + +Me.Visible = False +txtFilename.Text = "" +End Sub + + +Private Sub cmdFind_Click() + +If txtFilename.Enabled = False Then + Exit Sub +Else + +cdl1.DialogTitle = "Find Your Backup" +cdl1.InitDir = "c:\" +cdl1.ShowOpen + +If (cdl1.FileName <> "" And cdl1.CancelError = False) Then + txtFilename.Text = cdl1.FileName +End If + +End If + +End Sub + +Private Sub Form_Load() +optDevice.Value = True +cboDevices.Enabled = True +txtFilename.Enabled = False +txtFilename.BackColor = &H8000000F +cboDevices.BackColor = &H80000005 +ShowBackupDevices Form1.cboServers.Text +End Sub + +Private Sub Form_Paint() +'optDevice.Value = True +'cboDevices.Enabled = True +'txtFilename.Enabled = False +'txtFilename.BackColor = &H8000000F +'cboDevices.BackColor = &H80000005 +End Sub + +Private Sub optDevice_Click() +cboDevices.Enabled = True +txtFilename.Enabled = False +txtFilename.BackColor = &H8000000F +cboDevices.BackColor = &H80000005 +End Sub + +Private Sub optFile_Click() + +cboDevices.Enabled = False +txtFilename.Enabled = True +cboDevices.BackColor = &H8000000F +txtFilename.BackColor = &H80000005 +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/MSSCCPRJ.SCC b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/MSSCCPRJ.SCC new file mode 100644 index 0000000..1d6a7fa --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/MSSCCPRJ.SCC @@ -0,0 +1,5 @@ +[SCC] +SCC=This is a source code control file +[Project1.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Module1.bas b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Module1.bas new file mode 100644 index 0000000..1dfb447 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Module1.bas @@ -0,0 +1,12 @@ +Attribute VB_Name = "Module1" +Option Explicit + + +Public oServer As SQLDMO.SQLServer +Public oDevice As SQLDMO.BackupDevice +Public oDatabase As SQLDMO.Database +Public oBackup As SQLDMO.Backup +Public oRegisteredServer As SQLDMO.RegisteredServer +Public oApp As SQLDMO.Application +Public oRestore As SQLDMO.Restore +Public oGroup As SQLDMO.ServerGroup diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Project1.vbp b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Project1.vbp new file mode 100644 index 0000000..5a215bd --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Project1.vbp @@ -0,0 +1,40 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\stdole2.tlb#OLE Automation +Reference=*\G{10010001-E260-11CF-AE68-00AA004A34D5}#8.0#0#C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll#Microsoft SQLDMO Object Library +Form=Form1.frm +Object={5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0; MSFLXGRD.OCX +Object={BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0; tabctl32.ocx +Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; comdlg32.ocx +Form=Form2.frm +Module=Module1; Module1.bas +Object={00028C01-0000-0000-0000-000000000046}#1.0#0; DBGRID32.OCX +Object={CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0; MSDATGRD.OCX +Startup="Form1" +Command32="" +Name="Project1" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionCompanyName="Allison Mitchell" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Project1.vbw b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Project1.vbw new file mode 100644 index 0000000..edd7a0f --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Backups And restore/Code/Restoring The database/Project1.vbw @@ -0,0 +1,3 @@ +Form1 = 7, 19, 1240, 866, , 0, 0, 0, 0, C +Form2 = 94, 59, 1225, 889, C, 0, 0, 0, 0, C +Module1 = 597, 85, 1044, 917, C diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/FailedJob.ICO b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/FailedJob.ICO new file mode 100644 index 0000000..f62e1d1 Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/FailedJob.ICO differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/FailedStep.ICO b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/FailedStep.ICO new file mode 100644 index 0000000..8adf5e6 Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/FailedStep.ICO differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Form1.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Form1.frm new file mode 100644 index 0000000..1952d0d --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Form1.frm @@ -0,0 +1,861 @@ +VERSION 5.00 +Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx" +Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "msflxgrd.ocx" +Begin VB.Form frmJobsMain + Caption = "Main Job Viewer Form" + ClientHeight = 10005 + ClientLeft = 735 + ClientTop = 570 + ClientWidth = 14085 + LinkTopic = "Form1" + ScaleHeight = 10005 + ScaleWidth = 14085 + Begin VB.CommandButton cmdExit + Caption = "Exit" + Height = 345 + Left = 150 + TabIndex = 18 + Top = 9210 + Width = 13785 + End + Begin MSFlexGridLib.MSFlexGrid fg_JobHistory + Height = 1725 + Left = 120 + TabIndex = 15 + Top = 7380 + Width = 13845 + _ExtentX = 24421 + _ExtentY = 3043 + _Version = 393216 + Cols = 8 + FixedCols = 0 + FillStyle = 1 + AllowUserResizing= 3 + End + Begin VB.CommandButton cmdJobHistory + Caption = "Job History" + Height = 315 + Left = 150 + TabIndex = 11 + Top = 9630 + Width = 13785 + End + Begin VB.Frame frJobDetails + Caption = "Job Details" + BeginProperty Font + Name = "MS Sans Serif" + Size = 18 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = -1 'True + Strikethrough = 0 'False + EndProperty + Height = 6675 + Left = 8040 + TabIndex = 4 + Top = 210 + Width = 5865 + Begin VB.TextBox txtSchedule + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 1005 + Left = 210 + MultiLine = -1 'True + ScrollBars = 2 'Vertical + TabIndex = 16 + Top = 5430 + Width = 5385 + End + Begin VB.OptionButton optEnabled + Alignment = 1 'Right Justify + Caption = "Enabled" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 240 + TabIndex = 5 + Top = 810 + Width = 2025 + End + Begin VB.Label Label2 + Caption = "Schedule" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 225 + Left = 270 + TabIndex = 17 + Top = 5220 + Width = 2955 + End + Begin VB.Label lblCurrentRunStatus + Caption = "Current Run Status:" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 375 + Left = 240 + TabIndex = 14 + Top = 4800 + Width = 5565 + End + Begin VB.Label lblNextRunDate + Caption = "Next Run Date:" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 405 + Left = 240 + TabIndex = 13 + Top = 4174 + Width = 5505 + End + Begin VB.Label lblCategory + Caption = "Category:" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 315 + Left = 240 + TabIndex = 12 + Top = 3642 + Width = 5475 + End + Begin VB.Label lblLastRunDate + Caption = "Last Run Date" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 240 + TabIndex = 10 + Top = 1282 + Width = 5415 + End + Begin VB.Label lblOwner + Caption = "Owner" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 240 + TabIndex = 9 + Top = 3170 + Width = 5415 + End + Begin VB.Label lblDescription + Caption = "Description" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 240 + TabIndex = 8 + Top = 2698 + Width = 5415 + End + Begin VB.Label lblDateCreated + Caption = "Date Created:" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 240 + TabIndex = 7 + Top = 2226 + Width = 5415 + End + Begin VB.Label lblLastRunTime + Caption = "Last Run Time" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 240 + TabIndex = 6 + Top = 1754 + Width = 5415 + End + End + Begin MSComctlLib.ImageList il1 + Left = 3900 + Top = 5730 + _ExtentX = 1005 + _ExtentY = 1005 + BackColor = -2147483643 + ImageWidth = 32 + ImageHeight = 32 + MaskColor = 12632256 + _Version = 393216 + BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} + NumListImages = 7 + BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} + Picture = "Form1.frx":0000 + Key = "root" + EndProperty + BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} + Picture = "Form1.frx":031A + Key = "server" + EndProperty + BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} + Picture = "Form1.frx":076C + Key = "sjob" + EndProperty + BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} + Picture = "Form1.frx":0BBE + Key = "fjob" + EndProperty + BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} + Picture = "Form1.frx":1010 + Key = "sstep" + EndProperty + BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} + Picture = "Form1.frx":1462 + Key = "fstep" + EndProperty + BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} + Picture = "Form1.frx":18B4 + Key = "" + EndProperty + EndProperty + End + Begin VB.TextBox txtStepCommand + BackColor = &H80000000& + BeginProperty Font + Name = "MS Sans Serif" + Size = 13.5 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H000000FF& + Height = 1035 + Left = 150 + MultiLine = -1 'True + ScrollBars = 3 'Both + TabIndex = 2 + Top = 5910 + Width = 7785 + End + Begin VB.CommandButton cmdRefresh + Caption = "Refresh Tree" + Height = 495 + Left = 120 + TabIndex = 1 + Top = 4980 + Width = 7665 + End + Begin MSComctlLib.TreeView tv1 + Height = 4725 + Left = 150 + TabIndex = 0 + Top = 240 + Width = 7605 + _ExtentX = 13414 + _ExtentY = 8334 + _Version = 393217 + LineStyle = 1 + Style = 7 + ImageList = "il1" + Appearance = 0 + BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} + Name = "Comic Sans MS" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + End + Begin VB.Label Label3 + Caption = "Job History" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 225 + Left = 120 + TabIndex = 19 + Top = 7140 + Width = 4095 + End + Begin VB.Label Label1 + Caption = "Step Command" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 315 + Left = 180 + TabIndex = 3 + Top = 5520 + Width = 4725 + End +End +Attribute VB_Name = "frmJobsMain" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub LoadRegisteredServers() + +For Each oGroup In SQLDMO.ServerGroups + For Each oRserver In oGroup.RegisteredServers + tv1.Nodes.Add "ROOT", tvwChild, "SERVER_" & oRserver.Name, oRserver.Name, il1.ListImages(2).Key + tv1.Nodes.Add "SERVER_" & oRserver.Name, tvwChild, "DUMMY_" & oRserver.Name, "DUMMY" + Next oRserver +Next oGroup +End Sub + + +Private Sub LoadJobList(strServerclicked As String, strServerKey As String, intCountOfChildren As Integer, strFirstChildName As String, intFirstChildIndex As Integer) + +On Error GoTo err_handler + + +'Check if the server we are logged onto is +'the server we last used. If not log onto it +'if yes then carry on + +If strLastServerLoggedOnTo = "GOBBLEDYGOOK" Then + oServer.LoginSecure = True + oServer.Connect strServerclicked + strLastServerLoggedOnTo = strServerclicked +ElseIf strServerclicked <> strLastServerLoggedOnTo Then + oServer.DisConnect + oServer.LoginSecure = True + oServer.Connect strServerclicked + strLastServerLoggedOnTo = strServerclicked +End If + + +'check if the node has children and the first node's text is not DUMMY +'if yes then prepopulated so get out + +If intCountOfChildren > 0 And strFirstChildName <> "DUMMY" Then + Exit Sub +End If + +'If the first node is DUMMY then let's attempt a population + +If strFirstChildName = "DUMMY" Then + tv1.Nodes.Remove intFirstChildIndex + For Each oJob In oServer.JobServer.Jobs + If oJob.LastRunOutcome = SQLDMOJobOutcome_Succeeded Or oJob.LastRunOutcome = SQLDMOJobOutcome_Unknown Then + tv1.Nodes.Add "SERVER_" & strServerclicked, tvwChild, "JOB_" & strServerclicked & "_" & oJob.Name, oJob.Name, il1.ListImages(3).Key + ElseIf oJob.LastRunOutcome = SQLDMOJobOutcome_Failed Then + tv1.Nodes.Add "SERVER_" & strServerclicked, tvwChild, "JOB_" & strServerclicked & "_" & oJob.Name, oJob.Name, il1.ListImages(4).Key + End If + + tv1.Nodes.Add "JOB_" & strServerclicked & "_" & oJob.Name, tvwChild, "DUMMY_" & strServerclicked & "_" & oJob.Name, "DUMMY" + Next oJob +End If + +Exit Sub + +err_handler: +tv1.Nodes.Remove intFirstChildIndex +tv1.Nodes.Add "SERVER_" & strServerclicked, tvwChild, "ERROR_" & strServerclicked, "ERROR LOGGING INTO SERVER" + +Exit Sub +End Sub + + + +Private Sub ShowJobHistory(ServerName As String, JobName As String, booFailedOrAll As Boolean) + +Dim oJobHistory As SQLDMO.QueryResults +Dim i As Integer +Dim j As Integer + + +fg_JobHistory.Rows = 1 + +oServer.JobServer.JobHistoryFilter.JobName = JobName + +If booFailedOrAll = True Then + oServer.JobServer.JobHistoryFilter.OutcomeTypes = SQLDMOJobOutcome_Failed +End If + + +Set oJobHistory = oServer.JobServer.EnumJobHistory(oServer.JobServer.JobHistoryFilter) + + + For i = 1 To oJobHistory.Rows + fg_JobHistory.AddItem oJobHistory.GetColumnString(i, 3) & vbTab & oJobHistory.GetColumnString(i, 4) & vbTab & oJobHistory.GetColumnString(i, 5) & vbTab & oJobHistory.GetColumnString(i, 6) & vbTab & oJobHistory.GetColumnString(i, 7) & vbTab & oJobHistory.GetColumnString(i, 8) & vbTab & oJobHistory.GetColumnString(i, 9) & vbTab & oJobHistory.GetColumnString(i, 10) + Next i + + + + + + + +End Sub + +Private Sub cmdExit_Click() +Unload Me +End Sub + +Private Sub cmdJobHistory_Click() + +If Left(tv1.SelectedItem.Key, 4) = "JOB_" Then +fg_JobHistory.Rows = 1 +ShowJobHistory tv1.SelectedItem.Parent.Text, tv1.SelectedItem.Text, False +End If + +End Sub + +Private Sub cmdRefresh_Click() + +If strLastServerLoggedOnTo <> "GOBBLEDYGOOK" Then + oServer.DisConnect + strLastServerLoggedOnTo = "GOBBLEDYGOOK" +End If +tv1.Nodes.Clear +tv1.Nodes.Add , , "ROOT", "JOB SERVERS", il1.ListImages(1).Key +LoadRegisteredServers +ClearStepBoxes + +End Sub + +Private Sub cmdSchedule_Click() + +If Left(tv1.SelectedItem.Key, 4) = "JOB_" Then + ShowJobSchedule tv1.SelectedItem.Parent.Text, tv1.SelectedItem.Text +End If + +End Sub + +Private Sub Form_Load() +tv1.Nodes.Add , , "ROOT", "JOB SERVERS", il1.ListImages(1).Key +LoadRegisteredServers +End Sub + +Private Sub tv1_Expand(ByVal Node As MSComctlLib.Node) + +If Left(Node.Key, 6) = "SERVER" Then + LoadJobList Node.Text, Node.Key, Node.Children, Node.Child.Text, Node.Child.Index + ClearStepBoxes + +End If + +If Left(Node.Key, 3) = "JOB" Then + LoadJobStepList Node.Text, Node.Parent.Text, Node.Key, Node.Children, Node.Child.Text, Node.Child.Index +End If + +End Sub + +Private Sub ClearStepBoxes() +lblDateCreated = "Date Created:" +lblDescription = "Description" +lblLastRunDate = "Last Run Date" +lblLastRunTime = "Last Run Time" +lblOwner = "Owner" +lblCategory = "Category" +lblNextRunDate = "Next Run Date" +lblCurrentRunStatus = "Current Run Status" +txtStepCommand.Text = "" + +End Sub + +Private Sub LoadJobStepList(JobName As String, strServer As String, strJobKey As String, intCountOfChildren As Integer, strFirstChildName As String, intFirstChildIndex As Integer) + +On Error GoTo err_handler + +'do not need to check if the strLastServerLoggedOnTo is set to GOOBLEDYGOOK +'as if we can see the steps we've already logged in somewhere at least + + +If strServer <> strLastServerLoggedOnTo Then + oServer.DisConnect + oServer.LoginSecure = True + oServer.Connect strServer + strLastServerLoggedOnTo = strServer +End If + +'if count of children > 0 and first child is not dummy then we've populated +'so get out + +If intCountOfChildren > 0 And strFirstChildName <> "DUMMY" Then + Exit Sub +End If + +'If the first child is dummy then + +If strFirstChildName = "DUMMY" Then + tv1.Nodes.Remove intFirstChildIndex + For Each oJobStep In oServer.JobServer.Jobs(JobName).JobSteps + If oJobStep.LastRunOutcome = SQLDMOJobOutcome_Succeeded Or oJobStep.LastRunOutcome = SQLDMOJobOutcome_Unknown Then + tv1.Nodes.Add strJobKey, tvwChild, "JOBSTEP_" & JobName & "_" & oJobStep.Name, oJobStep.Name, il1.ListImages(5).Key + ElseIf oJobStep.LastRunOutcome = SQLDMOJobOutcome_Failed Then + tv1.Nodes.Add strJobKey, tvwChild, "JOBSTEP_" & JobName & "_" & oJobStep.Name, oJobStep.Name, il1.ListImages(6).Key + End If + Next oJobStep +End If + + +Exit Sub + + + +err_handler: + +Exit Sub +End Sub + +Public Sub ShowJobCommand(strServer As String, strJob As String, strJobStep As String) + +On Error GoTo err_handler + +Dim strStepCommand As String +txtStepCommand = "" + +'do not need to check if the strLastServerLoggedOnTo is set to GOOBLEDYGOOK +'as if we can see the steps we've already logged in somewhere at least +If strServer <> strLastServerLoggedOnTo Then + oServer.DisConnect + oServer.LoginSecure = True + oServer.Connect strServer + strLastServerLoggedOnTo = strServer +End If + +strStepCommand = oServer.JobServer.Jobs(strJob).JobSteps(strJobStep).Command + +txtStepCommand.Text = strStepCommand + + +Exit Sub + +err_handler: +MsgBox "error" +Exit Sub + +End Sub + +Private Sub tv1_NodeClick(ByVal Node As MSComctlLib.Node) + +If Left(Node.Key, 7) = "JOBSTEP" Then + ShowJobCommand Node.Parent.Parent.Text, Node.Parent.Text, Node.Text +End If + +If Left(Node.Key, 4) = "JOB_" Then + ShowJobDetails Node.Parent.Text, Node.Text + txtStepCommand.Text = "" +End If + +End Sub + + +Private Sub ShowJobDetails(strServer As String, JobName As String) + +Dim strCurrentRunStatus As String + +If strServer <> strLastServerLoggedOnTo Then + oServer.DisConnect + oServer.LoginSecure = True + oServer.Connect strServer + strLastServerLoggedOnTo = strServer +End If + +If oServer.JobServer.Jobs(JobName).Enabled = True Then + optEnabled.Value = True +Else + optEnabled.Value = False +End If + +lblDateCreated = "Date Created: " & oServer.JobServer.Jobs(JobName).DateCreated +lblDescription = "Description: " & oServer.JobServer.Jobs(JobName).Description +lblLastRunDate = "Last Run Date: " & Mid(oServer.JobServer.Jobs(JobName).LastRunDate, 7, 2) & "/" & Mid(oServer.JobServer.Jobs(JobName).LastRunDate, 5, 2) & "/" & Left(oServer.JobServer.Jobs(JobName).LastRunDate, 4) +lblLastRunTime = "Last Run Time: " & Mid(oServer.JobServer.Jobs(JobName).LastRunTime, 1, 2) & ":" & Mid(oServer.JobServer.Jobs(JobName).LastRunTime, 3, 2) & ":" & Mid(oServer.JobServer.Jobs(JobName).LastRunTime, 5, 2) +lblOwner = "Owner: " & oServer.JobServer.Jobs(JobName).Owner +lblCategory = "Category: " & oServer.JobServer.Jobs(JobName).Category +lblNextRunDate = "Next Run Date: " & Mid(oServer.JobServer.Jobs(JobName).NextRunDate, 7, 2) & "/" & Mid(oServer.JobServer.Jobs(JobName).NextRunDate, 5, 2) & "/" & Left(oServer.JobServer.Jobs(JobName).NextRunDate, 4) + + + + +Select Case oServer.JobServer.Jobs(JobName).CurrentRunStatus + +Case 0 +strCurrentRunStatus = "Unknown - Probably never run" +Case 1 +strCurrentRunStatus = "Executing" +Case 2 +strCurrentRunStatus = "Waiting for worker thread" +Case 3 +strCurrentRunStatus = "Between retries" +Case 4 +strCurrentRunStatus = "Idle" +Case 5 +strCurrentRunStatus = "Suspended" +Case 6 +strCurrentRunStatus = "Waiting for Step to Finish" +Case 7 +strCurrentRunStatus = "Performaing Completion Actions" +End Select + +lblCurrentRunStatus = "Current Run Status " & strCurrentRunStatus + +txtSchedule.Text = ShowJobSchedule(strServer, JobName) + + +End Sub + +Function IsBitSet(Src As Integer, Bit As Integer) As Boolean + IsBitSet = (Src And (2 ^ Bit)) <> 0 +End Function + + +Public Function ShowJobSchedule(strServerclicked As String, Job As String) As String + +Dim strFrequencyInterval As String +Dim strFreqTypeConstant As String +Dim strFreqInterval As String +Dim strSubType As String +Dim strCompleteScheduleString As String +Dim freqRelativeInterval As String + + +If oServer.JobServer.Jobs(Job).HasSchedule = False Then + ShowJobSchedule = "No Schedule Available" + Exit Function +End If + + +Select Case oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencySubDay +Case 0 +strSubType = "Unknown" +Case 1 +strSubType = "Once" +Case 4 +strSubType = "Minutes" +Case 8 +strSubType = "Hourly" +End Select + +Select Case oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyType +Case 0 +strFreqTypeConstant = "Unknown" +Case 1 +strFreqTypeConstant = "One Time" +strCompleteScheduleString = "This job will executute Once only on: " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartDate & " at: " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay +Case 4 +strFreqTypeConstant = "Daily" + +If strSubType = "Once" Then + strCompleteScheduleString = "This job will execute every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval & " days at " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay +ElseIf strSubType = "Minutes" Then + strCompleteScheduleString = "This job will execute every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval & " days and every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencySubDayInterval & " minutes between " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay & " and " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveEndTimeOfDay +ElseIf strSubType = "Hourly" Then + strCompleteScheduleString = "This job will execute every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval & " days and every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencySubDayInterval & " hours between " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay & " and " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveEndTimeOfDay +End If +Case 8 +strFreqTypeConstant = "Weekly" + +If (oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval And 1) Then +strFrequencyInterval = strFrequencyInterval + "Sunday," +End If + +If (oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval And 2) Then +strFrequencyInterval = strFrequencyInterval + "Monday," +End If + +If (oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval And 4) Then +strFrequencyInterval = strFrequencyInterval + "Tuesday," +End If + +If (oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval And 8) Then +strFrequencyInterval = strFrequencyInterval + "Wednesday," +End If + +If (oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval And 16) Then +strFrequencyInterval = strFrequencyInterval + "Thursday," +End If + +If (oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval And 32) Then +strFrequencyInterval = strFrequencyInterval + "Friday," +End If + +If (oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval And 64) Then +strFrequencyInterval = strFrequencyInterval + "Saturday," +End If + +If strSubType = "Once" Then + strCompleteScheduleString = "This job will execute on " & Left(strFrequencyInterval, Len(strFrequencyInterval) - 1) & " once only at " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay +ElseIf strSubType = "Minutes" Then + strCompleteScheduleString = "This job will execute on " & Left(strFrequencyInterval, Len(strFrequencyInterval) - 1) & " and every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencySubDayInterval & " minutes between " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay & " and " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveEndTimeOfDay +ElseIf strSubType = "Hourly" Then + strCompleteScheduleString = "This job will execute on " & Left(strFrequencyInterval, Len(strFrequencyInterval) - 1) & " and every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencySubDayInterval & " hours between " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay & " and " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveEndTimeOfDay +End If + +Case 16 +strFreqTypeConstant = "Monthly" + +If strSubType = "Once" Then + strCompleteScheduleString = "This job will execute on day " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval & " of the month every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRecurrenceFactor & " months once only at " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay +ElseIf strSubType = "Minutes" Then + strCompleteScheduleString = "This job will execute on day " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval & " of the month every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRecurrenceFactor & " months every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencySubDayInterval & " minutes between " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay & " and " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveEndTimeOfDay +ElseIf strSubType = "Hourly" Then + strCompleteScheduleString = "This job will execute on day " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval & " of the month every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRecurrenceFactor & " months every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencySubDayInterval & " hours between " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay & " and " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveEndTimeOfDay +End If +Case 32 +strFreqTypeConstant = "Monthly Relative" + +If oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval = 1 Then + strFrequencyInterval = "Sunday" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval = 2 Then + strFrequencyInterval = "Monday" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval = 3 Then + strFrequencyInterval = "Tuesday" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval = 4 Then + strFrequencyInterval = "Wednesday" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval = 5 Then + strFrequencyInterval = "Thursday" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval = 6 Then + strFrequencyInterval = "Friday" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval = 7 Then + strFrequencyInterval = "Saturday" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval = 8 Then + strFrequencyInterval = "Day" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval = 9 Then + strFrequencyInterval = "Weekday" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyInterval = 10 Then + strFrequencyInterval = "Weekendday" +End If + +If oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRelativeInterval = 1 Then + freqRelativeInterval = "First" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRelativeInterval = 2 Then + freqRelativeInterval = "Second" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRelativeInterval = 4 Then + freqRelativeInterval = "Third" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRelativeInterval = 8 Then + freqRelativeInterval = "Fourth" +ElseIf oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRelativeInterval = 16 Then + freqRelativeInterval = "Last" +End If + + + +If strSubType = "Once" Then + If strFrequencyInterval = "Day" Then + strCompleteScheduleString = "This job executes on the " & freqRelativeInterval & " day of every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRecurrenceFactor & " months once only at " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay + Else + strCompleteScheduleString = "This job executes on the " & freqRelativeInterval & " " & strFrequencyInterval & " of every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRecurrenceFactor & " months once only at " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay + End If + +ElseIf strSubType = "Minutes" Then + If strFrequencyInterval = "Day" Then + strCompleteScheduleString = "This job executes on the " & freqRelativeInterval & " day of every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRecurrenceFactor & " months every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencySubDayInterval & " minutes between " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay & " and " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveEndTimeOfDay + Else + strCompleteScheduleString = "This job executes on the " & freqRelativeInterval & " " & strFrequencyInterval & " of every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRecurrenceFactor & " months every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencySubDayInterval & " minutes between " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay & " and " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveEndTimeOfDay + End If + + +ElseIf strSubType = "Hourly" Then + If strFrequencyInterval = "Day" Then + strCompleteScheduleString = "This job executes on the " & freqRelativeInterval & " day of every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRecurrenceFactor & " months every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencySubDayInterval & " hours between " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay & " and " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveEndTimeOfDay + Else + strCompleteScheduleString = "This job executes on the " & freqRelativeInterval & " " & strFrequencyInterval & " of every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencyRecurrenceFactor & " months every " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.FrequencySubDayInterval & " hours between " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveStartTimeOfDay & " and " & oServer.JobServer.Jobs(Job).JobSchedules(1).Schedule.ActiveEndTimeOfDay + End If +End If + + +Case 64 +strFreqTypeConstant = "Autostart" + strCompleteScheduleString = "This job will execute when the SQL Server Agent Starts Up" +Case 128 +strFreqTypeConstant = "On Idle" + strCompleteScheduleString = "This job will execute when the CPU becomes idle" +End Select + + +ShowJobSchedule = strCompleteScheduleString + +End Function + diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Form1.frx b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Form1.frx new file mode 100644 index 0000000..d71c676 Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Form1.frx differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/MSSCCPRJ.SCC b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/MSSCCPRJ.SCC new file mode 100644 index 0000000..1d6a7fa --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/MSSCCPRJ.SCC @@ -0,0 +1,5 @@ +[SCC] +SCC=This is a source code control file +[Project1.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Module1.bas b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Module1.bas new file mode 100644 index 0000000..4b30491 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Module1.bas @@ -0,0 +1,22 @@ +Attribute VB_Name = "Module1" +Option Explicit + +Public strLastServerLoggedOnTo As String +Public oServer As New SQLDMO.SQLServer +Public oRserver As SQLDMO.RegisteredServer +Public oJob As SQLDMO.job +Public oJobStep As SQLDMO.JobStep +Public oGroup As SQLDMO.ServerGroup +Public oJobSchedule As SQLDMO.JobSchedule + + + +Sub main() + +strLastServerLoggedOnTo = "GOBBLEDYGOOK" +frmJobsMain.Show +End Sub + + + + diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/NotSelectedServer.ICO b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/NotSelectedServer.ICO new file mode 100644 index 0000000..6912bbc Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/NotSelectedServer.ICO differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Project1.csi b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Project1.csi new file mode 100644 index 0000000..81bade9 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Project1.csi @@ -0,0 +1,2 @@ +[History] +B0=Project1/frmJobsMain/ShowJobSchedule diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Project1.vbp b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Project1.vbp new file mode 100644 index 0000000..4f7957f --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Project1.vbp @@ -0,0 +1,37 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\..\..\WINDOWS\System32\stdole2.tlb#OLE Automation +Reference=*\G{10010001-E260-11CF-AE68-00AA004A34D5}#7.0#0#..\..\..\..\..\..\..\..\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll#Microsoft SQLDMO Object Library +Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; mscomctl.ocx +Form=Form1.frm +Module=Module1; Module1.bas +Object={5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0; msflxgrd.ocx +Startup="Sub Main" +HelpFile="" +Command32="" +Name="Project1" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionCompanyName="CMPI" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Project1.vbw b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Project1.vbw new file mode 100644 index 0000000..1b02711 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/Project1.vbw @@ -0,0 +1,2 @@ +frmJobsMain = 43, 51, 970, 670, C, 0, 0, 0, 0, C +Module1 = 65, 46, 899, 596, C diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/ROOT.ICO b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/ROOT.ICO new file mode 100644 index 0000000..add2ffa Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/ROOT.ICO differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/SelectedServer.ICO b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/SelectedServer.ICO new file mode 100644 index 0000000..4e72182 Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/SelectedServer.ICO differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/SuccessfulJob.ICO b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/SuccessfulJob.ICO new file mode 100644 index 0000000..0d1bc90 Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/SuccessfulJob.ICO differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/SuccessfulStep.ICO b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/SuccessfulStep.ICO new file mode 100644 index 0000000..2eb7ca6 Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/SuccessfulStep.ICO differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/stillgoing.ICO b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/stillgoing.ICO new file mode 100644 index 0000000..c786ddb Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/JobViewerApp/stillgoing.ICO differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/Form1.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/Form1.frm new file mode 100644 index 0000000..b940aab --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/Form1.frm @@ -0,0 +1,51 @@ +VERSION 5.00 +Begin VB.Form frmSplash + BorderStyle = 0 'None + Caption = "Form1" + ClientHeight = 1065 + ClientLeft = 3600 + ClientTop = 4485 + ClientWidth = 12450 + LinkTopic = "Form1" + ScaleHeight = 1065 + ScaleWidth = 12450 + ShowInTaskbar = 0 'False + Begin VB.Label lblInfo + Alignment = 2 'Center + Caption = "Attempting Login to..." + BeginProperty Font + Name = "MS Sans Serif" + Size = 24 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 645 + Left = 0 + TabIndex = 0 + Top = 210 + Width = 12465 + End +End +Attribute VB_Name = "frmSplash" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub Form_Load() +Me.Show , frmLogin + +End Sub + +Public Sub InformUser(ByVal strMessage As String) + + lblInfo.Caption = strMessage + 'make sure the display refreshes + DoEvents + +End Sub + diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/MSSCCPRJ.SCC b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/MSSCCPRJ.SCC new file mode 100644 index 0000000..cad5796 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/MSSCCPRJ.SCC @@ -0,0 +1,5 @@ +[SCC] +SCC=This is a source code control file +[prj_NewOperator.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/Module1.bas b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/Module1.bas new file mode 100644 index 0000000..32ad9c6 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/Module1.bas @@ -0,0 +1,6 @@ +Attribute VB_Name = "Module1" +Option Explicit + +Public oServer As New SQLDMO.SQLServer +Public oOperator As SQLDMO.Operator + diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/frmLogin.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/frmLogin.frm new file mode 100644 index 0000000..9c79cbd --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/frmLogin.frm @@ -0,0 +1,173 @@ +VERSION 5.00 +Begin VB.Form frmLogin + BorderStyle = 3 'Fixed Dialog + Caption = "Login" + ClientHeight = 2820 + ClientLeft = 6105 + ClientTop = 4830 + ClientWidth = 3750 + LinkTopic = "Form1" + MaxButton = 0 'False + MinButton = 0 'False + ScaleHeight = 1666.149 + ScaleMode = 0 'User + ScaleWidth = 3521.047 + ShowInTaskbar = 0 'False + Begin VB.CheckBox chkTrusted + Alignment = 1 'Right Justify + Caption = "Trusted Connection" + Height = 225 + Left = 150 + TabIndex = 4 + Top = 1620 + Width = 2025 + End + Begin VB.TextBox txtServer + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + Left = 1320 + TabIndex = 1 + Top = 360 + Width = 2325 + End + Begin VB.TextBox txtUserName + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + Left = 1320 + TabIndex = 2 + Top = 795 + Width = 2325 + End + Begin VB.CommandButton cmdOK + Caption = "OK" + Default = -1 'True + Height = 390 + Left = 510 + TabIndex = 5 + Top = 2070 + Width = 1140 + End + Begin VB.CommandButton cmdCancel + Cancel = -1 'True + Caption = "Cancel" + Height = 390 + Left = 2130 + TabIndex = 6 + Top = 2070 + Width = 1140 + End + Begin VB.TextBox txtPassword + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + IMEMode = 3 'DISABLE + Left = 1320 + PasswordChar = "*" + TabIndex = 3 + Top = 1185 + Width = 2325 + End + Begin VB.Label Label1 + Caption = "Server" + Height = 225 + Left = 135 + TabIndex = 8 + Top = 450 + Width = 1155 + End + Begin VB.Label lblLabels + Caption = "&User Name:" + Height = 270 + Index = 0 + Left = 135 + TabIndex = 0 + Top = 810 + Width = 1080 + End + Begin VB.Label lblLabels + Caption = "&Password:" + Height = 270 + Index = 1 + Left = 135 + TabIndex = 7 + Top = 1200 + Width = 1080 + End +End +Attribute VB_Name = "frmLogin" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False + +Private Sub chkTrusted_Click() +If chkTrusted.Value = vbChecked Then + txtUserName.Enabled = False + txtPassword.Enabled = False +Else + txtUserName.Enabled = True + txtPassword.Enabled = True +End If + +End Sub + +Private Sub cmdCancel_Click() +Unload Me + +End Sub + +Private Sub cmdOK_Click() + +On Error GoTo err_handler + + +If chkTrusted.Value = vbChecked Then + oServer.LoginSecure = True + oServer.Connect txtServer.Text +Else + If txtServer.Text <> "" And txtUserName <> "" Then + oServer.Login = txtUserName.Text + oServer.Password = txtPassword.Text + Else + Exit Sub + End If +End If + + +frmNewOperator.Visible = True +Unload Me + +Exit Sub + +err_handler: + +MsgBox "An Error Occured" +Exit Sub + + + + +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/frmNewOperator.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/frmNewOperator.frm new file mode 100644 index 0000000..8e26997 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/frmNewOperator.frm @@ -0,0 +1,622 @@ +VERSION 5.00 +Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "tabctl32.ocx" +Begin VB.Form frmNewOperator + Caption = "New Operator" + ClientHeight = 7935 + ClientLeft = 5895 + ClientTop = 3405 + ClientWidth = 6480 + LinkTopic = "Form1" + ScaleHeight = 7935 + ScaleWidth = 6480 + Begin TabDlg.SSTab SSTab1 + Height = 7935 + Left = 0 + TabIndex = 0 + Top = 0 + Width = 6495 + _ExtentX = 11456 + _ExtentY = 13996 + _Version = 393216 + Tabs = 1 + TabHeight = 520 + TabCaption(0) = "General" + TabPicture(0) = "frmNewOperator.frx":0000 + Tab(0).ControlEnabled= -1 'True + Tab(0).Control(0)= "Label1" + Tab(0).Control(0).Enabled= 0 'False + Tab(0).Control(1)= "Label2" + Tab(0).Control(1).Enabled= 0 'False + Tab(0).Control(2)= "Label3" + Tab(0).Control(2).Enabled= 0 'False + Tab(0).Control(3)= "Label4" + Tab(0).Control(3).Enabled= 0 'False + Tab(0).Control(4)= "Label5" + Tab(0).Control(4).Enabled= 0 'False + Tab(0).Control(5)= "Label6" + Tab(0).Control(5).Enabled= 0 'False + Tab(0).Control(6)= "Label7" + Tab(0).Control(6).Enabled= 0 'False + Tab(0).Control(7)= "Label8" + Tab(0).Control(7).Enabled= 0 'False + Tab(0).Control(8)= "Label9" + Tab(0).Control(8).Enabled= 0 'False + Tab(0).Control(9)= "txtName" + Tab(0).Control(9).Enabled= 0 'False + Tab(0).Control(10)= "cmdCheckName" + Tab(0).Control(10).Enabled= 0 'False + Tab(0).Control(11)= "txtmail" + Tab(0).Control(11).Enabled= 0 'False + Tab(0).Control(12)= "txtPager" + Tab(0).Control(12).Enabled= 0 'False + Tab(0).Control(13)= "txtNetSend" + Tab(0).Control(13).Enabled= 0 'False + Tab(0).Control(14)= "chkMonday" + Tab(0).Control(14).Enabled= 0 'False + Tab(0).Control(15)= "chkTuesday" + Tab(0).Control(15).Enabled= 0 'False + Tab(0).Control(16)= "chkWednesday" + Tab(0).Control(16).Enabled= 0 'False + Tab(0).Control(17)= "chkFriday" + Tab(0).Control(17).Enabled= 0 'False + Tab(0).Control(18)= "chkSaturday" + Tab(0).Control(18).Enabled= 0 'False + Tab(0).Control(19)= "chkSunday" + Tab(0).Control(19).Enabled= 0 'False + Tab(0).Control(20)= "cboWeekdayStart" + Tab(0).Control(20).Enabled= 0 'False + Tab(0).Control(21)= "cboWeekDayEnd" + Tab(0).Control(21).Enabled= 0 'False + Tab(0).Control(22)= "cboWeekendStart" + Tab(0).Control(22).Enabled= 0 'False + Tab(0).Control(23)= "cboWeekendEnd" + Tab(0).Control(23).Enabled= 0 'False + Tab(0).Control(24)= "cmdAdd" + Tab(0).Control(24).Enabled= 0 'False + Tab(0).Control(25)= "chkThursday" + Tab(0).Control(25).Enabled= 0 'False + Tab(0).ControlCount= 26 + Begin VB.CheckBox chkThursday + Caption = "Thursday" + Height = 255 + Left = 510 + TabIndex = 26 + Tag = "16" + Top = 5190 + Width = 2085 + End + Begin VB.CommandButton cmdAdd + Caption = "Add" + Height = 405 + Left = 4740 + TabIndex = 25 + Top = 7320 + Width = 1065 + End + Begin VB.ComboBox cboWeekendEnd + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 360 + Left = 3720 + TabIndex = 22 + Top = 6630 + Width = 1515 + End + Begin VB.ComboBox cboWeekendStart + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 360 + Left = 3720 + TabIndex = 21 + Top = 6300 + Width = 1515 + End + Begin VB.ComboBox cboWeekDayEnd + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 360 + Left = 3780 + TabIndex = 18 + Top = 5100 + Width = 1455 + End + Begin VB.ComboBox cboWeekdayStart + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 360 + Left = 3780 + TabIndex = 17 + Top = 4800 + Width = 1455 + End + Begin VB.CheckBox chkSunday + Caption = "Sunday" + Height = 165 + Left = 480 + TabIndex = 16 + Tag = "1" + Top = 6660 + Width = 2355 + End + Begin VB.CheckBox chkSaturday + Caption = "Saturday" + Height = 195 + Left = 480 + TabIndex = 15 + Tag = "64" + Top = 6360 + Width = 2355 + End + Begin VB.CheckBox chkFriday + Caption = "Friday" + Height = 195 + Left = 510 + TabIndex = 14 + Tag = "32" + Top = 5520 + Width = 2355 + End + Begin VB.CheckBox chkWednesday + Caption = "Wednesday" + Height = 195 + Left = 510 + TabIndex = 13 + Tag = "8" + Top = 4920 + Width = 2355 + End + Begin VB.CheckBox chkTuesday + Caption = "Tuesday" + Height = 195 + Left = 510 + TabIndex = 12 + Tag = "4" + Top = 4650 + Width = 2355 + End + Begin VB.CheckBox chkMonday + Caption = "Monday" + Height = 195 + Left = 510 + TabIndex = 11 + Tag = "2" + Top = 4350 + Width = 2355 + End + Begin VB.TextBox txtNetSend + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H000000FF& + Height = 315 + Left = 1350 + TabIndex = 9 + Top = 3240 + Width = 3525 + End + Begin VB.TextBox txtPager + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H000000FF& + Height = 315 + Left = 1350 + TabIndex = 7 + Top = 2490 + Width = 3555 + End + Begin VB.TextBox txtmail + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H000000FF& + Height = 315 + Left = 1350 + TabIndex = 4 + Top = 1740 + Width = 3525 + End + Begin VB.CommandButton cmdCheckName + Caption = "Check" + Height = 375 + Left = 4980 + TabIndex = 3 + Top = 930 + Width = 1065 + End + Begin VB.TextBox txtName + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H00FF0000& + Height = 345 + Left = 1320 + TabIndex = 1 + Top = 930 + Width = 3525 + End + Begin VB.Label Label9 + Caption = "End" + Height = 255 + Left = 5370 + TabIndex = 24 + Top = 6690 + Width = 765 + End + Begin VB.Label Label8 + Caption = "Start" + Height = 195 + Left = 5340 + TabIndex = 23 + Top = 6360 + Width = 825 + End + Begin VB.Label Label7 + Caption = "End" + Height = 255 + Left = 5370 + TabIndex = 20 + Top = 5130 + Width = 405 + End + Begin VB.Label Label6 + Caption = "Start" + Height = 225 + Left = 5340 + TabIndex = 19 + Top = 4830 + Width = 945 + End + Begin VB.Label Label5 + Caption = "Pager Days" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 225 + Left = 360 + TabIndex = 10 + Top = 3960 + Width = 1065 + End + Begin VB.Label Label4 + Caption = "Net Send" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 315 + Left = 270 + TabIndex = 8 + Top = 3240 + Width = 1035 + End + Begin VB.Label Label3 + Caption = "Pager" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + Left = 300 + TabIndex = 6 + Top = 2490 + Width = 825 + End + Begin VB.Label Label2 + Caption = "E-Mail" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 315 + Left = 330 + TabIndex = 5 + Top = 1770 + Width = 855 + End + Begin VB.Label Label1 + Caption = "Name:" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 300 + TabIndex = 2 + Top = 1020 + Width = 945 + End + End +End +Attribute VB_Name = "frmNewOperator" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + + +Dim PagerDays As String + +Private Sub FillComboBoxes() + +Dim hr As Integer +Dim min As Integer +Dim sec As Integer +Dim i As Integer +Dim strTime As String +Dim ctl As Control + + +For i = 0 To 24 + + + For Each ctl In frmNewOperator.Controls + If TypeOf ctl Is ComboBox Then + If i <> 24 Then + ctl.AddItem CStr(i) & ":" & "00" & ":" & "00" + ctl.AddItem CStr(i) & ":" & "30" & ":" & "00" + End If + End If + Next ctl + + +Next i +End Sub + +Private Sub DisablePagerDays() +Dim ctl As Control + +For Each ctl In Me.Controls + If TypeOf ctl Is CheckBox Or TypeOf ctl Is ComboBox Then + ctl.Enabled = False + End If +Next ctl + +End Sub + +Private Sub EnablePagerDays() +Dim ctl As Control + +For Each ctl In Me.Controls + If TypeOf ctl Is CheckBox Or TypeOf ctl Is ComboBox Then + ctl.Enabled = True + End If +Next ctl + +End Sub + +Private Sub ClearUpAfterwards() + +Dim ctl As Control + + +For Each ctl In Controls + If TypeOf ctl Is CheckBox Then + ctl.Value = vbUnchecked + End If + + If TypeOf ctl Is TextBox Then + ctl.Text = "" + End If + +Next ctl + + + +End Sub + +Private Sub cmdAdd_Click() + +On Error GoTo err_handler + + + +If txtName.Text = "" Or CheckOperators(txtName.Text) = True Then + Exit Sub +Else + +Set oOperator = New SQLDMO.Operator + +With oOperator + .Name = txtName + + If txtmail.Text <> "" Then + + .EmailAddress = txtmail.Text + + End If + + If txtPager.Text <> "" Then + .PagerAddress = txtPager.Text + .PagerDays = CheckPagerDays + + If HaveWeGotPagerDaysInWeek = True Then + .WeekdayPagerStartTime = cboWeekdayStart.Text + .WeekdayPagerEndTime = cboWeekDayEnd.Text + End If + + If HaveWeGotPagerDaysInWeekend = True Then + .SaturdayPagerStartTime = cboWeekendStart.Text + .SaturdayPagerEndTime = cboWeekendEnd.Text + .SundayPagerStartTime = cboWeekendStart.Text + .SundayPagerEndTime = cboWeekendEnd.Text + End If + End If + +End With + +End If + + + + + +oServer.JobServer.Operators.Add oOperator +ClearUpAfterwards + +Exit Sub + +err_handler: + +MsgBox Err.Description +Exit Sub + +End Sub + +Private Sub cmdCheckName_Click() +CheckOperators (txtName.Text) + +End Sub + + +Private Function CheckOperators(strOperatorName As String) As Boolean + +CheckOperators = False + +For Each oOperator In oServer.JobServer.Operators + If oOperator.Name = strOperatorName Then + CheckOperators = True + MsgBox "An Operator With That Name Already Exists", vbInformation, "Already Exists" + End If +Next oOperator + + +End Function + +Private Sub Form_Load() +FillComboBoxes +DisablePagerDays + +End Sub + +Private Function CheckPagerDays() As Integer + + +Dim ctl As Control + +CheckPagerDays = 0 + +For Each ctl In frmNewOperator.Controls + If TypeOf ctl Is CheckBox Then + If ctl.Value = vbChecked Then + MsgBox ctl.Tag + CheckPagerDays = CheckPagerDays + ctl.Tag + MsgBox CheckPagerDays + End If + End If +Next ctl + + + +End Function + +Private Function HaveWeGotPagerDaysInWeek() As Boolean + +HaveWeGotPagerDaysInWeek = False + +If chkMonday.Value = vbChecked Or chkTuesday.Value = vbChecked Or chkWednesday.Value = vbChecked Or chkThursday.Value = vbChecked Or chkFriday.Value = vbChecked Then + HaveWeGotPagerDaysInWeek = True +End If + +End Function + +Private Function HaveWeGotPagerDaysInWeekend() As Boolean + +HaveWeGotPagerDaysInWeekend = False + +If chkSaturday.Value = vbChecked Or chkSunday.Value Then + HaveWeGotPagerDaysInWeekend = True +End If + +End Function + + +Private Sub txtPager_Change() +If Len(txtPager.Text) > 0 Then + EnablePagerDays +Else + DisablePagerDays +End If + +End Sub + + diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/frmNewOperator.frx b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/frmNewOperator.frx new file mode 100644 index 0000000..24838bf Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/frmNewOperator.frx differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/prj_NewOperator.vbp b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/prj_NewOperator.vbp new file mode 100644 index 0000000..d1d33cc --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/prj_NewOperator.vbp @@ -0,0 +1,37 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\stdole2.tlb#OLE Automation +Reference=*\G{10010001-E260-11CF-AE68-00AA004A34D5}#8.0#0#C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll#Microsoft SQLDMO Object Library +Object={BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0; tabctl32.ocx +Form=frmNewOperator.frm +Form=frmLogin.frm +Module=Module1; Module1.bas +Startup="frmLogin" +HelpFile="" +Command32="" +Name="prj_NewOperator" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionCompanyName="AM Ltd" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/prj_NewOperator.vbw b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/prj_NewOperator.vbw new file mode 100644 index 0000000..5ce6afe --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/New Operator/prj_NewOperator.vbw @@ -0,0 +1,3 @@ +frmNewOperator = 158, 184, 1119, 1019, , 0, 0, 0, 0, C +frmLogin = 367, 82, 1118, 810, C, 0, 0, 0, 0, C +Module1 = 258, 159, 705, 700, C diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/FrmJobStep.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/FrmJobStep.frm new file mode 100644 index 0000000..5c62a45 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/FrmJobStep.frm @@ -0,0 +1,256 @@ +VERSION 5.00 +Begin VB.Form FrmJobStep + Caption = "Job Step" + ClientHeight = 6300 + ClientLeft = 3225 + ClientTop = 3225 + ClientWidth = 9195 + LinkTopic = "Form1" + ScaleHeight = 6300 + ScaleWidth = 9195 + Begin VB.ComboBox cboOnfailureAction + Height = 315 + Left = 5850 + TabIndex = 10 + Top = 4380 + Width = 1905 + End + Begin VB.ComboBox cboOnSuccessAction + Height = 315 + Left = 5850 + TabIndex = 9 + Top = 3810 + Width = 1905 + End + Begin VB.TextBox txtStepText + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H000000FF& + Height = 1425 + Left = 2160 + MultiLine = -1 'True + ScrollBars = 2 'Vertical + TabIndex = 7 + Top = 1920 + Width = 5535 + End + Begin VB.ComboBox cboDatabase + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H000000FF& + Height = 360 + Left = 2160 + TabIndex = 5 + Top = 1440 + Width = 5535 + End + Begin VB.TextBox txtStepName + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H000000FF& + Height = 315 + Left = 2190 + TabIndex = 2 + Top = 570 + Width = 5535 + End + Begin VB.CommandButton cmdCancel + Caption = "Cancel" + Height = 585 + Left = 7290 + TabIndex = 1 + Top = 5550 + Width = 1515 + End + Begin VB.CommandButton cmdAdd + Caption = "Add" + Height = 585 + Left = 5610 + TabIndex = 0 + Top = 5550 + Width = 1515 + End + Begin VB.Label Label6 + Caption = "Failure" + Height = 195 + Left = 5190 + TabIndex = 12 + Top = 4440 + Width = 555 + End + Begin VB.Label Label5 + Caption = "Success" + Height = 225 + Left = 5160 + TabIndex = 11 + Top = 3870 + Width = 645 + End + Begin VB.Label Label4 + Caption = "Step Text" + Height = 345 + Left = 1050 + TabIndex = 8 + Top = 1920 + Width = 1095 + End + Begin VB.Label Label3 + Caption = "Database" + Height = 255 + Left = 990 + TabIndex = 6 + Top = 1500 + Width = 1155 + End + Begin VB.Label Label2 + Alignment = 2 'Center + Caption = "Transact SQL Step" + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 405 + Left = 1740 + TabIndex = 4 + Top = 960 + Width = 5205 + End + Begin VB.Label Label1 + Caption = "Step Name" + Height = 285 + Left = 960 + TabIndex = 3 + Top = 630 + Width = 1245 + End +End +Attribute VB_Name = "FrmJobStep" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + + + +Private Sub GetJobStepCredentials() + +Dim OjobSuccessAction As SQLDMO.SQLDMO_JOBSTEPACTION_TYPE +Dim OjobFailureAction As SQLDMO.SQLDMO_JOBSTEPACTION_TYPE + + +Select Case cboOnSuccessAction.Text + +Case "Quit With Success" +OjobSuccessAction = 1 +Case "Quit With Failure" +OjobSuccessAction = 2 +Case "Goto Next Step" +OjobSuccessAction = 3 +End Select + + +Select Case cboOnfailureAction.Text + +Case "Quit With Success" +OjobFailureAction = 1 +Case "Quit With Failure" +OjobFailureAction = 2 +Case "Goto Next Step" +OjobFailureAction = 3 +End Select + + + +Set OJobStep = New SQLDMO.JobStep + + + + +OJobStep.stepid = stepid + 1 +OJobStep.Name = txtStepName.Text +OJobStep.DatabaseName = cboDatabase.Text +OJobStep.SubSystem = "TSQL" +OJobStep.Command = txtStepText.Text +OJobStep.OnSuccessAction = OjobSuccessAction +OJobStep.OnFailAction = OjobFailureAction + + +oServer.JobServer.Jobs(strJobName).JobSteps.Add OJobStep +AddToStepList stepid, OJobStep.Name, OJobStep.SubSystem, cboOnSuccessAction.Text, cboOnfailureAction.Text + +stepid = stepid + 1 + +Unload Me + + +End Sub + +Private Sub AddToStepList(intstepid As Integer, strStepname As String, strStepType As String, strOnsuccess As String, strOnfailure As String) +frmJobBuilder.msf_JobStep.AddItem intstepid & vbTab & strStepname & vbTab & strStepType & vbTab & strOnsuccess & vbTab & strOnfailure +End Sub + +Private Sub cmdAdd_Click() +If txtStepName.Text <> "" Then + GetJobStepCredentials +End If + +End Sub + +Private Sub cmdCancel_Click() +Me.Visible = False +End Sub + + Private Sub LoadDatabases() + For Each odatabase In oServer.Databases + cboDatabase.AddItem odatabase.Name +Next odatabase + +cboDatabase.ListIndex = 1 + End Sub + +Sub loadActions() +cboOnfailureAction.AddItem "Quit With Success" +cboOnfailureAction.AddItem "Quit With Failure" +cboOnfailureAction.AddItem "Goto Next Step" + +cboOnSuccessAction.AddItem "Quit With Success" +cboOnSuccessAction.AddItem "Quit With Failure" +cboOnSuccessAction.AddItem "Goto Next Step" + +cboOnfailureAction.ListIndex = 1 +cboOnSuccessAction.ListIndex = 0 + +End Sub + +Private Sub Form_Load() +LoadDatabases +loadActions + +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/MSSCCPRJ.SCC b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/MSSCCPRJ.SCC new file mode 100644 index 0000000..1d6a7fa --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/MSSCCPRJ.SCC @@ -0,0 +1,5 @@ +[SCC] +SCC=This is a source code control file +[Project1.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/Module1.bas b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/Module1.bas new file mode 100644 index 0000000..10a3d78 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/Module1.bas @@ -0,0 +1,15 @@ +Attribute VB_Name = "Module1" +Option Explicit + +Public oServer As New SQLDMO.SQLServer +Public odatabase As SQLDMO.Database +Public ojob As SQLDMO.Job +Public stepid As Integer +Public OJobStep As SQLDMO.JobStep +Public strJobName As String + +Public oJobSchedule As New SQLDMO.JobSchedule + + + + diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/Project1.vbp b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/Project1.vbp new file mode 100644 index 0000000..66f0474 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/Project1.vbp @@ -0,0 +1,41 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\stdole2.tlb#OLE Automation +Reference=*\G{10010001-E260-11CF-AE68-00AA004A34D5}#7.0#0#C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll#Microsoft SQLDMO Object Library +Object={BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0; tabctl32.ocx +Object={5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0; MSFLXGRD.OCX +Object={86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0; MSCOMCT2.OCX +Form=frmJobBuilder.frm +Form=FrmJobStep.frm +Module=Module1; Module1.bas +Form=frmLogin.frm +IconForm="frmJobBuilder" +Startup="frmLogin" +HelpFile="" +Command32="" +Name="Project1" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionCompanyName="Allison Mitchell" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/Project1.vbw b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/Project1.vbw new file mode 100644 index 0000000..a3e695d --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/Project1.vbw @@ -0,0 +1,4 @@ +frmJobBuilder = 28, 53, 980, 611, C, 0, 0, 0, 0, C +FrmJobStep = 17, 89, 927, 630, C, 0, 0, 0, 0, C +Module1 = 224, 135, 923, 676, C +frmLogin = 121, 113, 762, 654, C, 0, 0, 0, 0, C diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/frmJobBuilder.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/frmJobBuilder.frm new file mode 100644 index 0000000..e73f65a --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/frmJobBuilder.frm @@ -0,0 +1,1401 @@ +VERSION 5.00 +Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "tabctl32.ocx" +Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX" +Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX" +Begin VB.Form frmJobBuilder + Caption = "JobBuilder" + ClientHeight = 6780 + ClientLeft = 3495 + ClientTop = 4455 + ClientWidth = 13080 + LinkTopic = "Form1" + ScaleHeight = 6780 + ScaleWidth = 13080 + Begin TabDlg.SSTab STAB1 + Height = 6825 + Left = -30 + TabIndex = 0 + Top = 0 + Width = 13095 + _ExtentX = 23098 + _ExtentY = 12039 + _Version = 393216 + Tabs = 4 + Tab = 2 + TabsPerRow = 4 + TabHeight = 520 + TabCaption(0) = "General" + TabPicture(0) = "frmJobBuilder.frx":0000 + Tab(0).ControlEnabled= 0 'False + Tab(0).Control(0)= "cmdExit" + Tab(0).Control(1)= "cmdAddJob" + Tab(0).Control(2)= "txtDescription" + Tab(0).Control(3)= "cboOwner" + Tab(0).Control(4)= "cboCategory" + Tab(0).Control(5)= "txtJobName" + Tab(0).Control(6)= "chkEnabled" + Tab(0).Control(7)= "Label4" + Tab(0).Control(8)= "lblDateCreated" + Tab(0).Control(9)= "Label3" + Tab(0).Control(10)= "Label2" + Tab(0).Control(11)= "Label1" + Tab(0).ControlCount= 12 + TabCaption(1) = "Job" + TabPicture(1) = "frmJobBuilder.frx":001C + Tab(1).ControlEnabled= 0 'False + Tab(1).Control(0)= "msf_JobStep" + Tab(1).Control(1)= "cmdAddStep" + Tab(1).ControlCount= 2 + TabCaption(2) = "Schedule" + TabPicture(2) = "frmJobBuilder.frx":0038 + Tab(2).ControlEnabled= -1 'True + Tab(2).Control(0)= "Label7" + Tab(2).Control(0).Enabled= 0 'False + Tab(2).Control(1)= "lblEvery" + Tab(2).Control(1).Enabled= 0 'False + Tab(2).Control(2)= "lblInterval" + Tab(2).Control(2).Enabled= 0 'False + Tab(2).Control(3)= "Line2" + Tab(2).Control(3).Enabled= 0 'False + Tab(2).Control(4)= "lblOnceADay" + Tab(2).Control(4).Enabled= 0 'False + Tab(2).Control(5)= "lblOccursAt" + Tab(2).Control(5).Enabled= 0 'False + Tab(2).Control(6)= "lblStart" + Tab(2).Control(6).Enabled= 0 'False + Tab(2).Control(7)= "lblEnd" + Tab(2).Control(7).Enabled= 0 'False + Tab(2).Control(8)= "lblAt" + Tab(2).Control(8).Enabled= 0 'False + Tab(2).Control(9)= "lblOn" + Tab(2).Control(9).Enabled= 0 'False + Tab(2).Control(10)= "txtScheduleName" + Tab(2).Control(10).Enabled= 0 'False + Tab(2).Control(11)= "txtWeekDayInterval" + Tab(2).Control(11).Enabled= 0 'False + Tab(2).Control(12)= "txtOnceADay" + Tab(2).Control(12).Enabled= 0 'False + Tab(2).Control(13)= "txtRecurringEvery" + Tab(2).Control(13).Enabled= 0 'False + Tab(2).Control(14)= "lstMinuteHour" + Tab(2).Control(14).Enabled= 0 'False + Tab(2).Control(15)= "txtStartsAt" + Tab(2).Control(15).Enabled= 0 'False + Tab(2).Control(16)= "txtEndsAt" + Tab(2).Control(16).Enabled= 0 'False + Tab(2).Control(17)= "chkSunday" + Tab(2).Control(17).Enabled= 0 'False + Tab(2).Control(18)= "chkMonday" + Tab(2).Control(18).Enabled= 0 'False + Tab(2).Control(19)= "chkTuesday" + Tab(2).Control(19).Enabled= 0 'False + Tab(2).Control(20)= "chkWednesday" + Tab(2).Control(20).Enabled= 0 'False + Tab(2).Control(21)= "chkThursday" + Tab(2).Control(21).Enabled= 0 'False + Tab(2).Control(22)= "chkFriday" + Tab(2).Control(22).Enabled= 0 'False + Tab(2).Control(23)= "chkSaturday" + Tab(2).Control(23).Enabled= 0 'False + Tab(2).Control(24)= "cmdAddSchedule" + Tab(2).Control(24).Enabled= 0 'False + Tab(2).Control(25)= "optOnceADay" + Tab(2).Control(25).Enabled= 0 'False + Tab(2).Control(26)= "Frame1" + Tab(2).Control(26).Enabled= 0 'False + Tab(2).Control(27)= "txtAt" + Tab(2).Control(27).Enabled= 0 'False + Tab(2).Control(28)= "dtOn" + Tab(2).Control(28).Enabled= 0 'False + Tab(2).Control(29)= "optRecurring" + Tab(2).Control(29).Enabled= 0 'False + Tab(2).ControlCount= 30 + TabCaption(3) = "Notifications" + TabPicture(3) = "frmJobBuilder.frx":0054 + Tab(3).ControlEnabled= 0 'False + Tab(3).Control(0)= "cmdNotification" + Tab(3).Control(1)= "cboNetSendLevel" + Tab(3).Control(2)= "cboPagelevel" + Tab(3).Control(3)= "cboMailLevel" + Tab(3).Control(4)= "cboNetSendOperator" + Tab(3).Control(5)= "cboPageOperator" + Tab(3).Control(6)= "cboEmailOperator" + Tab(3).Control(7)= "chkNetSend" + Tab(3).Control(8)= "chkPage" + Tab(3).Control(9)= "chkEmail" + Tab(3).Control(10)= "Label6" + Tab(3).Control(11)= "Label5" + Tab(3).ControlCount= 12 + Begin VB.OptionButton optRecurring + Height = 225 + Left = 3240 + TabIndex = 60 + Top = 4980 + Width = 345 + End + Begin MSComCtl2.DTPicker dtOn + Height = 435 + Left = 6510 + TabIndex = 59 + Top = 1890 + Width = 1935 + _ExtentX = 3413 + _ExtentY = 767 + _Version = 393216 + BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} + Name = "MS Sans Serif" + Size = 13.5 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Format = 22740993 + CurrentDate = 37291 + End + Begin VB.TextBox txtAt + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 375 + Left = 9150 + TabIndex = 56 + Top = 1890 + Width = 1185 + End + Begin VB.Frame Frame1 + Caption = "Intervals" + Height = 3555 + Left = 120 + TabIndex = 50 + Top = 1320 + Width = 2715 + Begin VB.OptionButton optAutoRun + Caption = "Run when SQL Server starts" + Height = 225 + Left = 180 + TabIndex = 55 + Top = 330 + Width = 2355 + End + Begin VB.OptionButton optCPUIdle + Caption = "When CPU Becomes Idle" + Height = 195 + Left = 180 + TabIndex = 54 + Top = 990 + Width = 2145 + End + Begin VB.OptionButton optOneTimeOnly + Caption = "One Time Only" + Height = 225 + Left = 180 + TabIndex = 53 + Top = 1680 + Width = 1425 + End + Begin VB.OptionButton optDaily + Caption = "Daily" + Height = 225 + Left = 180 + TabIndex = 52 + Top = 2340 + Width = 1065 + End + Begin VB.OptionButton optWeekly + Caption = "Weekly" + Height = 285 + Left = 180 + TabIndex = 51 + Top = 3000 + Width = 1095 + End + End + Begin VB.OptionButton optOnceADay + Height = 255 + Left = 3240 + TabIndex = 49 + Top = 4140 + Width = 345 + End + Begin VB.CommandButton cmdAddSchedule + Caption = "Add Schedule" + Height = 615 + Left = 10440 + TabIndex = 48 + Top = 5970 + Width = 1635 + End + Begin VB.CheckBox chkSaturday + Caption = "Saturday" + Height = 255 + Left = 10140 + TabIndex = 47 + Top = 2970 + Width = 1005 + End + Begin VB.CheckBox chkFriday + Caption = "Friday" + Height = 255 + Left = 9080 + TabIndex = 46 + Top = 2970 + Width = 1005 + End + Begin VB.CheckBox chkThursday + Caption = "Thursday" + Height = 255 + Left = 8020 + TabIndex = 45 + Top = 2970 + Width = 1005 + End + Begin VB.CheckBox chkWednesday + Caption = "Wednesday" + Height = 255 + Left = 6750 + TabIndex = 44 + Top = 2970 + Width = 1215 + End + Begin VB.CheckBox chkTuesday + Caption = "Tuesday" + Height = 255 + Left = 5690 + TabIndex = 43 + Top = 2970 + Width = 1005 + End + Begin VB.CheckBox chkMonday + Caption = "Monday" + Height = 255 + Left = 4630 + TabIndex = 42 + Top = 2970 + Width = 1005 + End + Begin VB.CheckBox chkSunday + Caption = "Sunday" + Height = 255 + Left = 3570 + TabIndex = 41 + Top = 2970 + Width = 1005 + End + Begin VB.TextBox txtEndsAt + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + Left = 9450 + TabIndex = 38 + Top = 5190 + Width = 1185 + End + Begin VB.TextBox txtStartsAt + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 360 + Left = 9450 + TabIndex = 37 + Top = 4650 + Width = 1185 + End + Begin VB.ListBox lstMinuteHour + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 300 + ItemData = "frmJobBuilder.frx":0070 + Left = 6630 + List = "frmJobBuilder.frx":007A + TabIndex = 36 + Top = 4920 + Width = 1695 + End + Begin VB.TextBox txtRecurringEvery + BeginProperty Font + Name = "MS Sans Serif" + Size = 24 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 525 + Left = 5730 + TabIndex = 35 + Top = 4860 + Width = 675 + End + Begin VB.TextBox txtOnceADay + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 315 + Left = 5820 + TabIndex = 33 + Top = 4050 + Width = 945 + End + Begin VB.TextBox txtWeekDayInterval + BeginProperty Font + Name = "MS Sans Serif" + Size = 24 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 555 + Left = 5700 + TabIndex = 29 + Top = 2100 + Width = 645 + End + Begin VB.TextBox txtScheduleName + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 360 + Left = 4350 + TabIndex = 27 + Top = 1200 + Width = 6015 + End + Begin VB.CommandButton cmdNotification + Caption = "Set Notification" + Height = 585 + Left = -64230 + TabIndex = 26 + Top = 5940 + Width = 1665 + End + Begin VB.CommandButton cmdExit + Caption = "Exit" + Height = 465 + Left = -64080 + TabIndex = 25 + Top = 6030 + Width = 1785 + End + Begin MSFlexGridLib.MSFlexGrid msf_JobStep + Height = 3795 + Left = -73020 + TabIndex = 24 + Top = 1200 + Width = 8715 + _ExtentX = 15372 + _ExtentY = 6694 + _Version = 393216 + Rows = 1 + Cols = 5 + FixedRows = 0 + FixedCols = 0 + AllowUserResizing= 3 + End + Begin VB.CommandButton cmdAddJob + Caption = "Add Job" + Height = 465 + Left = -64080 + TabIndex = 23 + Top = 5430 + Width = 1755 + End + Begin VB.ComboBox cboNetSendLevel + Height = 315 + Left = -66870 + TabIndex = 22 + Top = 2970 + Width = 2925 + End + Begin VB.ComboBox cboPagelevel + Height = 315 + Left = -66870 + TabIndex = 21 + Top = 2460 + Width = 2925 + End + Begin VB.ComboBox cboMailLevel + Height = 315 + Left = -66870 + TabIndex = 20 + Top = 1890 + Width = 2955 + End + Begin VB.ComboBox cboNetSendOperator + Height = 315 + Left = -72030 + TabIndex = 17 + Top = 3000 + Width = 3105 + End + Begin VB.ComboBox cboPageOperator + Height = 315 + Left = -72030 + TabIndex = 16 + Top = 2490 + Width = 3135 + End + Begin VB.ComboBox cboEmailOperator + Height = 315 + Left = -72030 + TabIndex = 15 + Top = 1860 + Width = 3105 + End + Begin VB.CheckBox chkNetSend + Caption = "Net Send" + Height = 345 + Left = -73950 + TabIndex = 14 + Top = 3030 + Width = 1095 + End + Begin VB.CheckBox chkPage + Caption = "Page" + Height = 255 + Left = -73920 + TabIndex = 13 + Top = 2460 + Width = 765 + End + Begin VB.CheckBox chkEmail + Caption = "Email" + Height = 255 + Left = -73920 + TabIndex = 12 + Top = 1860 + Width = 735 + End + Begin VB.CommandButton cmdAddStep + Caption = "Add Step" + Height = 525 + Left = -64620 + TabIndex = 11 + Top = 5280 + Width = 1695 + End + Begin VB.TextBox txtDescription + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 2025 + Left = -72240 + TabIndex = 9 + Top = 4020 + Width = 5505 + End + Begin VB.ComboBox cboOwner + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 360 + Left = -72240 + TabIndex = 5 + Top = 3240 + Width = 4695 + End + Begin VB.ComboBox cboCategory + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 360 + Left = -72270 + TabIndex = 4 + Top = 2610 + Width = 4725 + End + Begin VB.TextBox txtJobName + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 360 + Left = -72240 + TabIndex = 2 + Top = 1020 + Width = 5565 + End + Begin VB.CheckBox chkEnabled + Caption = "Enabled" + Height = 255 + Left = -65760 + TabIndex = 1 + Top = 1020 + Width = 1005 + End + Begin VB.Label lblOn + Caption = "On" + BeginProperty Font + Name = "MS Sans Serif" + Size = 18 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 375 + Left = 5880 + TabIndex = 58 + Top = 1860 + Width = 615 + End + Begin VB.Label lblAt + Caption = "At" + BeginProperty Font + Name = "MS Sans Serif" + Size = 13.5 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 315 + Left = 8640 + TabIndex = 57 + Top = 1920 + Width = 375 + End + Begin VB.Label lblEnd + Caption = "Ends" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 225 + Left = 8850 + TabIndex = 40 + Top = 5280 + Width = 435 + End + Begin VB.Label lblStart + Caption = "Start" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 225 + Left = 8850 + TabIndex = 39 + Top = 4740 + Width = 435 + End + Begin VB.Label lblOccursAt + Caption = "Occurs Every" + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 285 + Left = 3750 + TabIndex = 34 + Top = 4950 + Width = 1725 + End + Begin VB.Label lblOnceADay + Caption = "Once a Day at" + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + Left = 3840 + TabIndex = 32 + Top = 4050 + Width = 1815 + End + Begin VB.Line Line2 + X1 = 3840 + X2 = 9990 + Y1 = 3660 + Y2 = 3660 + End + Begin VB.Label lblInterval + BeginProperty Font + Name = "MS Sans Serif" + Size = 24 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 645 + Left = 6540 + TabIndex = 31 + Top = 2100 + Width = 1725 + End + Begin VB.Label lblEvery + Caption = "Every" + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 315 + Left = 4770 + TabIndex = 30 + Top = 2250 + Width = 795 + End + Begin VB.Label Label7 + Caption = "Name:" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 3660 + TabIndex = 28 + Top = 1260 + Width = 645 + End + Begin VB.Label Label6 + Caption = "On Action" + BeginProperty Font + Name = "MS Sans Serif" + Size = 18 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 525 + Left = -66510 + TabIndex = 19 + Top = 1140 + Width = 3225 + End + Begin VB.Label Label5 + Alignment = 2 'Center + Caption = "Operator" + BeginProperty Font + Name = "MS Sans Serif" + Size = 18 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 525 + Left = -71970 + TabIndex = 18 + Top = 1140 + Width = 2895 + End + Begin VB.Label Label4 + Caption = "Description" + Height = 285 + Left = -73320 + TabIndex = 10 + Top = 4050 + Width = 1065 + End + Begin VB.Label lblDateCreated + Caption = "Date Created" + Height = 195 + Left = -72270 + TabIndex = 8 + Top = 1830 + Width = 4965 + End + Begin VB.Label Label3 + Caption = "Owner" + Height = 255 + Left = -73320 + TabIndex = 7 + Top = 3270 + Width = 1065 + End + Begin VB.Label Label2 + Caption = "Category" + Height = 225 + Left = -73290 + TabIndex = 6 + Top = 2610 + Width = 1035 + End + Begin VB.Label Label1 + Caption = "Job Name:" + Height = 285 + Left = -73320 + TabIndex = 3 + Top = 1050 + Width = 1035 + End + End +End +Attribute VB_Name = "frmJobBuilder" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub chkEmail_Click() +ShallWeMail +End Sub + +Private Sub chkNetSend_Click() +ShallWeNetSend +End Sub + +Private Sub chkPage_Click() +ShallWePage +End Sub + +Private Function JobExists(JobName) As Boolean + +JobExists = False + +For Each ojob In oServer.JobServer.Jobs + If ojob.Name = JobName Then + JobExists = True + End If +Next ojob + +End Function + +Private Sub AnyNotifications() + +Dim oOutcomeLevel As SQLDMO.SQLDMO_COMPLETION_TYPE + + +'Email +If chkEmail.Value = vbChecked And cboMailLevel.Text <> "" And cboEmailOperator.Text <> "" Then + +Select Case cboMailLevel.Text + + Case "On Success" + oOutcomeLevel = 1 + Case "On Failure" + oOutcomeLevel = 2 + Case "On Completion" + oOutcomeLevel = 3 +End Select + + oServer.JobServer.Jobs(strJobName).BeginAlter + oServer.JobServer.Jobs(strJobName).EmailLevel = oOutcomeLevel + oServer.JobServer.Jobs(strJobName).OperatorToEmail = "ALLAN" + oServer.JobServer.Jobs(strJobName).DoAlter + +End If + + +'Page +If chkPage.Value = vbChecked And cboPagelevel.Text <> "" And cboPageOperator.Text <> "" Then + + + Select Case cboPagelevel.Text + + Case "On Success" + oOutcomeLevel = 1 + Case "On Failure" + oOutcomeLevel = 2 + Case "On Completion" + oOutcomeLevel = 3 + End Select + + oServer.JobServer.Jobs(strJobName).BeginAlter + oServer.JobServer.Jobs(strJobName).OperatorToPage = cboPageOperator.Text + oServer.JobServer.Jobs(strJobName).PageLevel = oOutcomeLevel + oServer.JobServer.Jobs(strJobName).DoAlter + +End If + + + +'Net Send +If chkNetSend.Value = vbChecked And cboNetSendLevel.Text <> "" And cboNetSendOperator.Text <> "" Then + + + Select Case cboNetSendLevel.Text + + Case "On Success" + oOutcomeLevel = 1 + Case "On Failure" + oOutcomeLevel = 2 + Case "On Completion" + oOutcomeLevel = 3 + End Select + + oServer.JobServer.Jobs(strJobName).BeginAlter + oServer.JobServer.Jobs(strJobName).OperatorToNetSend = cboNetSendOperator.Text + oServer.JobServer.Jobs(strJobName).NetSendLevel = oOutcomeLevel + oServer.JobServer.Jobs(strJobName).DoAlter + +End If +End Sub + + +Private Sub cmdAddJob_Click() + +If txtJobName.Text <> "" And JobExists(txtJobName.Text) = False Then + Set ojob = New SQLDMO.Job + ojob.Name = txtJobName.Text + ojob.Category = cboCategory.Text + ojob.Owner = cboOwner.Text + ojob.Description = txtDescription.Text + + 'ojob.EmailLevel = SQLDMOComp_Success + 'ojob.OperatorToEmail = "ALLAN" + + If chkEnabled.Value = vbChecked Then + ojob.Enabled = True + Else + ojob.Enabled = False + End If + + + oServer.JobServer.Jobs.Add ojob + strJobName = ojob.Name +End If + + +End Sub + +Private Sub cmdAddSchedule_Click() + +If optAutoRun.Value = True Then + SQLServerStartSchedule txtScheduleName.Text +ElseIf optCPUIdle.Value = True Then + CPUIdleSchedule txtScheduleName.Text +ElseIf optOneTimeOnly.Value = True Then + OneTimeOnlySchedule txtScheduleName.Text, dtOn.Year & IIf(Len(dtOn.Month) <> 2, "0" & dtOn.Month, dtOn.Month) & IIf(Len(dtOn.Day) <> 2, "0" & dtOn.Day, dtOn.Day), txtAt.Text +ElseIf optDaily.Value = True Then + If optOnceADay.Value = True Then + DailySchedule txtScheduleName.Text, txtWeekDayInterval.Text, True, txtOnceADay.Text + Else + If lstMinuteHour.Text = "Minute" Then + DailySchedule txtScheduleName.Text, txtWeekDayInterval.Text, False, , txtRecurringEvery.Text, 1, txtStartsAt.Text, txtEndsAt.Text + Else + DailySchedule txtScheduleName.Text, txtWeekDayInterval.Text, False, , txtRecurringEvery.Text, 2, txtStartsAt.Text, txtEndsAt.Text + End If + End If + +ElseIf optWeekly.Value = True Then + + If optOnceADay.Value = True Then + WeeklySchedule txtScheduleName.Text, txtWeekDayInterval.Text, True, txtOnceADay.Text, , , , , DaysOfWeekToRun + Else + If lstMinuteHour.Text <> "Hour" Then + WeeklySchedule txtScheduleName.Text, txtWeekDayInterval.Text, False, , txtRecurringEvery.Text, 1, txtStartsAt.Text, txtEndsAt.Text, DaysOfWeekToRun + Else + WeeklySchedule txtScheduleName.Text, txtWeekDayInterval.Text, False, , txtRecurringEvery.Text, 2, txtStartsAt.Text, txtEndsAt.Text, DaysOfWeekToRun + End If + End If + + +End If + + + +End Sub + +Private Sub cmdAddStep_Click() +FrmJobStep.Visible = True +End Sub + +Private Sub cmdExit_Click() +Unload Me +End Sub + +Private Sub cmdNotification_Click() +AnyNotifications +End Sub + +Private Sub Form_Load() +lblDateCreated.Caption = "Date Created: " & Now() +LoadCategories +LoadOwners +LoadOperators +loadActions +ShallWeMail +ShallWeNetSend +ShallWePage +msf_JobStep.Rows = 0 +HideAllScheduleControls +optAutoRun.Value = True + +cboCategory.ListIndex = 1 + + + + +End Sub + +Private Sub ShallWeMail() +If chkEmail.Value = vbChecked Then + cboEmailOperator.Enabled = True + cboMailLevel.Enabled = True +Else + cboEmailOperator.Enabled = False + cboMailLevel.Enabled = False +End If +End Sub + +Private Sub ShallWeNetSend() +If chkNetSend.Value = vbChecked Then + cboNetSendOperator.Enabled = True + cboNetSendLevel.Enabled = True +Else + cboNetSendOperator.Enabled = False + cboNetSendLevel.Enabled = False +End If +End Sub + +Private Sub ShallWePage() +If chkPage.Value = vbChecked Then + cboPageOperator.Enabled = True + cboPagelevel.Enabled = True +Else + cboPageOperator.Enabled = False + cboPagelevel.Enabled = False +End If +End Sub + +Private Sub loadActions() + +cboMailLevel.AddItem "On Success" +cboMailLevel.AddItem "On Failure" +cboMailLevel.AddItem "On Completion" + +cboPagelevel.AddItem "On Success" +cboPagelevel.AddItem "On Failure" +cboPagelevel.AddItem "On Completion" + +cboNetSendLevel.AddItem "On Success" +cboNetSendLevel.AddItem "On Failure" +cboNetSendLevel.AddItem "On Completion" + + + + +End Sub + + +Private Sub LoadOperators() +Dim ooperator As New SQLDMO.Operator +For Each ooperator In oServer.JobServer.Operators + cboPageOperator.AddItem ooperator.Name + cboNetSendOperator.AddItem ooperator.Name + cboEmailOperator.AddItem ooperator.Name +Next ooperator + + +End Sub + +Private Sub LoadOwners() +Dim ologin As New SQLDMO.Login + +For Each ologin In oServer.Logins + cboOwner.AddItem ologin.Name +Next ologin + +End Sub +Private Sub LoadCategories() + +Dim ocategory As New SQLDMO.Category + +For Each ocategory In oServer.JobServer.JobCategories + cboCategory.AddItem ocategory.Name +Next ocategory +End Sub + + +Private Sub HideAllScheduleControls() +lblOn.Visible = False +dtOn.Visible = False +lblAt.Visible = False +txtAt.Visible = False +lblEvery.Visible = False +txtWeekDayInterval.Visible = False +lblInterval.Visible = False +chkSunday.Visible = False +chkMonday.Visible = False +chkTuesday.Visible = False +chkWednesday.Visible = False +chkThursday.Visible = False +chkFriday.Visible = False +chkSaturday.Visible = False +optOnceADay.Visible = False +optRecurring.Visible = False +lblOnceADay.Visible = False +txtOnceADay.Visible = False +lblOccursAt.Visible = False +txtRecurringEvery.Visible = False +lstMinuteHour.Visible = False +lblStart.Visible = False +lblEnd.Visible = False +txtStartsAt.Visible = False +txtEndsAt.Visible = False + + + +End Sub + + +Private Sub HideAllScheduleControlsExceptWeekly() +lblOn.Visible = False +dtOn.Visible = False +lblAt.Visible = False +txtAt.Visible = False +lblEvery.Visible = True +txtWeekDayInterval.Visible = True +lblInterval.Visible = True +lblInterval.Caption = "Weeks" +chkSunday.Visible = True +chkMonday.Visible = True +chkTuesday.Visible = True +chkWednesday.Visible = True +chkThursday.Visible = True +chkFriday.Visible = True +chkSaturday.Visible = True +optOnceADay.Visible = True +optRecurring.Visible = True +lblOnceADay.Visible = True +txtOnceADay.Visible = True +lblOccursAt.Visible = True +txtRecurringEvery.Visible = True +lstMinuteHour.Visible = True +lblStart.Visible = True +lblEnd.Visible = True +txtStartsAt.Visible = True +txtEndsAt.Visible = True + + + +End Sub + + + + +Private Sub HideAllScheduleControlsExceptDaily() +lblOn.Visible = False +dtOn.Visible = False +lblAt.Visible = False +txtAt.Visible = False +lblEvery.Visible = True +txtWeekDayInterval.Visible = True +lblInterval.Visible = True +lblInterval.Caption = "Days" +chkSunday.Visible = False +chkMonday.Visible = False +chkTuesday.Visible = False +chkWednesday.Visible = False +chkThursday.Visible = False +chkFriday.Visible = False +chkSaturday.Visible = False +optOnceADay.Visible = True +optRecurring.Visible = True +lblOnceADay.Visible = True +txtOnceADay.Visible = True +lblOccursAt.Visible = True +txtRecurringEvery.Visible = True +lstMinuteHour.Visible = True +lblStart.Visible = True +lblEnd.Visible = True +txtStartsAt.Visible = True +txtEndsAt.Visible = True + + + +End Sub + + + +Private Sub HideAllScheduleControlsExceptOnceOnly() +lblOn.Visible = True +dtOn.Visible = True +lblAt.Visible = True +txtAt.Visible = True +lblEvery.Visible = False +txtWeekDayInterval.Visible = False +lblInterval.Visible = False +chkSunday.Visible = False +chkMonday.Visible = False +chkTuesday.Visible = False +chkWednesday.Visible = False +chkThursday.Visible = False +chkFriday.Visible = False +chkSaturday.Visible = False +optOnceADay.Visible = False +optRecurring.Visible = False +lblOnceADay.Visible = False +txtOnceADay.Visible = False +lblOccursAt.Visible = False +txtRecurringEvery.Visible = False +lstMinuteHour.Visible = False +lblStart.Visible = False +lblEnd.Visible = False +txtStartsAt.Visible = False +txtEndsAt.Visible = False + + + +End Sub + + +Private Sub optAutoRun_Click() +HideAllScheduleControls +End Sub + +Private Sub optCPUIdle_Click() +HideAllScheduleControls +End Sub + +Private Sub optDaily_Click() +HideAllScheduleControlsExceptDaily +End Sub + +Private Sub optOneTimeOnly_Click() +HideAllScheduleControlsExceptOnceOnly +End Sub + +Private Sub optWeekly_Click() +HideAllScheduleControlsExceptWeekly +End Sub + + +Private Sub SQLServerStartSchedule(strschedulename As String) + + +oJobSchedule.Schedule.FrequencyType = SQLDMOFreq_Autostart +oJobSchedule.Name = strschedulename + + +With oServer.JobServer.Jobs(strJobName) + .BeginAlter + .JobSchedules.Add oJobSchedule +End With + + +End Sub + +Private Sub CPUIdleSchedule(strschedulename As String) +oJobSchedule.Schedule.FrequencyType = SQLDMOFreq_OnIdle +oJobSchedule.Name = strschedulename + + +With oServer.JobServer.Jobs(strJobName) + .BeginAlter + .JobSchedules.Add oJobSchedule +End With +End Sub + +Private Sub OneTimeOnlySchedule(strschedulename As String, strWhen As String, strAtTime As String) +oJobSchedule.Schedule.FrequencyType = SQLDMOFreq_OneTime +oJobSchedule.Schedule.ActiveStartDate = strWhen +oJobSchedule.Schedule.ActiveStartTimeOfDay = strAtTime +oJobSchedule.Name = strschedulename + +With oServer.JobServer.Jobs(strJobName) + .BeginAlter + .JobSchedules.Add oJobSchedule +End With +End Sub + + +Private Function DaysOfWeekToRun() As Integer + +DaysOfWeekToRun = 0 + +If chkSunday.Value = vbChecked Then + DaysOfWeekToRun = DaysOfWeekToRun + 1 +End If + +If chkMonday.Value = vbChecked Then + DaysOfWeekToRun = DaysOfWeekToRun + 2 +End If + +If chkTuesday.Value = vbChecked Then + DaysOfWeekToRun = DaysOfWeekToRun + 4 +End If + +If chkWednesday.Value = vbChecked Then + DaysOfWeekToRun = DaysOfWeekToRun + 8 +End If + +If chkThursday.Value = vbChecked Then + DaysOfWeekToRun = DaysOfWeekToRun + 16 +End If + +If chkFriday.Value = vbChecked Then + DaysOfWeekToRun = DaysOfWeekToRun + 32 +End If + +If chkSaturday.Value = vbChecked Then + DaysOfWeekToRun = DaysOfWeekToRun + 64 +End If + + + + +End Function + +Private Sub DailySchedule(strschedulename As String, intDailyInterval As Integer, booOnce As Boolean, Optional strOnceOnlyTime As String, Optional intRecurrenceInterval As Integer, Optional intMinHour As Integer, Optional strStartTime As String, Optional strEndTime As String) +oJobSchedule.Schedule.FrequencyType = SQLDMOFreq_Daily +oJobSchedule.Schedule.FrequencyInterval = intDailyInterval +oJobSchedule.Name = strschedulename + + +If booOnce = True Then + oJobSchedule.Schedule.ActiveStartTimeOfDay = strOnceOnlyTime +Else + + oJobSchedule.Schedule.FrequencySubDayInterval = intRecurrenceInterval + + If intMinHour = 1 Then 'Minute + oJobSchedule.Schedule.FrequencySubDay = 4 + Else 'hours + oJobSchedule.Schedule.FrequencySubDay = 8 + End If + + oJobSchedule.Schedule.ActiveStartTimeOfDay = strStartTime + oJobSchedule.Schedule.ActiveEndTimeOfDay = strEndTime + +End If + + + + + oServer.JobServer.Jobs(strJobName).BeginAlter + oServer.JobServer.Jobs(strJobName).JobSchedules.Add oJobSchedule + oServer.JobServer.Jobs(strJobName).DoAlter + + +End Sub + + +Private Sub WeeklySchedule(strschedulename As String, intWeeklyInterval As Integer, booOnce As Boolean, Optional strOnceOnlyTime As String, Optional intRecurrenceInterval As Integer, Optional intMinHour As Integer, Optional strStartTime As String, Optional strEndTime As String, Optional intOnDays As Integer) +oJobSchedule.Schedule.FrequencyType = SQLDMOFreq_Weekly +oJobSchedule.Schedule.FrequencyInterval = intOnDays +oJobSchedule.Name = strschedulename +oJobSchedule.Schedule.FrequencyRecurrenceFactor = intWeeklyInterval + +If booOnce = True Then + oJobSchedule.Schedule.ActiveStartTimeOfDay = strOnceOnlyTime +Else + + + + If intMinHour = 1 Then 'Minute + oJobSchedule.Schedule.FrequencySubDay = 4 + Else 'hours + oJobSchedule.Schedule.FrequencySubDay = 8 + End If + + oJobSchedule.Schedule.ActiveStartTimeOfDay = strStartTime + oJobSchedule.Schedule.ActiveEndTimeOfDay = strEndTime + oJobSchedule.Schedule.FrequencySubDayInterval = intRecurrenceInterval + + +End If + + + + + oServer.JobServer.Jobs(strJobName).BeginAlter + oServer.JobServer.Jobs(strJobName).JobSchedules.Add oJobSchedule + oServer.JobServer.Jobs(strJobName).DoAlter + + +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/frmJobBuilder.frx b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/frmJobBuilder.frx new file mode 100644 index 0000000..c8141be Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/frmJobBuilder.frx differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/frmLogin.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/frmLogin.frm new file mode 100644 index 0000000..c86f9a6 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Jobs And Alerts/Code/NewJob/frmLogin.frm @@ -0,0 +1,173 @@ +VERSION 5.00 +Begin VB.Form frmLogin + BorderStyle = 3 'Fixed Dialog + Caption = "Login" + ClientHeight = 2820 + ClientLeft = 6105 + ClientTop = 4830 + ClientWidth = 3750 + LinkTopic = "Form1" + MaxButton = 0 'False + MinButton = 0 'False + ScaleHeight = 1666.149 + ScaleMode = 0 'User + ScaleWidth = 3521.047 + ShowInTaskbar = 0 'False + Begin VB.CheckBox chkTrusted + Alignment = 1 'Right Justify + Caption = "Trusted Connection" + Height = 225 + Left = 150 + TabIndex = 4 + Top = 1620 + Width = 2025 + End + Begin VB.TextBox txtServer + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + Left = 1320 + TabIndex = 1 + Top = 360 + Width = 2325 + End + Begin VB.TextBox txtUserName + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + Left = 1320 + TabIndex = 2 + Top = 795 + Width = 2325 + End + Begin VB.CommandButton cmdOK + Caption = "OK" + Default = -1 'True + Height = 390 + Left = 510 + TabIndex = 5 + Top = 2070 + Width = 1140 + End + Begin VB.CommandButton cmdCancel + Cancel = -1 'True + Caption = "Cancel" + Height = 390 + Left = 2130 + TabIndex = 6 + Top = 2070 + Width = 1140 + End + Begin VB.TextBox txtPassword + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + IMEMode = 3 'DISABLE + Left = 1320 + PasswordChar = "*" + TabIndex = 3 + Top = 1185 + Width = 2325 + End + Begin VB.Label Label1 + Caption = "Server" + Height = 225 + Left = 135 + TabIndex = 8 + Top = 450 + Width = 1155 + End + Begin VB.Label lblLabels + Caption = "&User Name:" + Height = 270 + Index = 0 + Left = 135 + TabIndex = 0 + Top = 810 + Width = 1080 + End + Begin VB.Label lblLabels + Caption = "&Password:" + Height = 270 + Index = 1 + Left = 135 + TabIndex = 7 + Top = 1200 + Width = 1080 + End +End +Attribute VB_Name = "frmLogin" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False + +Private Sub chkTrusted_Click() +If chkTrusted.Value = vbChecked Then + txtUserName.Enabled = False + txtPassword.Enabled = False +Else + txtUserName.Enabled = True + txtPassword.Enabled = True +End If + +End Sub + +Private Sub cmdCancel_Click() +Unload Me + +End Sub + +Private Sub cmdOK_Click() + +On Error GoTo err_handler + + +If chkTrusted.Value = vbChecked Then + oServer.LoginSecure = True + oServer.Connect txtServer.Text +Else + If txtServer.Text <> "" And txtUserName <> "" Then + oServer.Login = txtUserName.Text + oServer.Password = txtPassword.Text + Else + Exit Sub + End If +End If + + +frmJobBuilder.Visible = True +Unload Me + +Exit Sub + +err_handler: + +MsgBox "An Error Occured" +Exit Sub + + + + +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/MSSCCPRJ.SCC b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/MSSCCPRJ.SCC new file mode 100644 index 0000000..1d6a7fa --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/MSSCCPRJ.SCC @@ -0,0 +1,5 @@ +[SCC] +SCC=This is a source code control file +[Project1.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/Module1.bas b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/Module1.bas new file mode 100644 index 0000000..0c20859 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/Module1.bas @@ -0,0 +1,16 @@ +Attribute VB_Name = "Module1" +Option Explicit + +Public oGroup As SQLDMO.ServerGroup +Public oRServer As SQLDMO.RegisteredServer +Public oServer As SQLDMO.SQLServer +Public oDatabase As SQLDMO.Database +Public oLogin As SQLDMO.Login +Public oUser As SQLDMO.User +Public oSRole As SQLDMO.ServerRole +Public oDBRole As SQLDMO.DatabaseRole +Public oNameList As SQLDMO.NameList +Public Const DO_NOTHING = 0 +Public Const IS_MEMBER = 1 +Public Const NEEDS_ADDING = 2 +Public Const NEEDS_DELETING = 3 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/Project1.csi b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/Project1.csi new file mode 100644 index 0000000..107ddc5 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/Project1.csi @@ -0,0 +1,3 @@ +[History] +B0=Project1/frmDBRoles +B1=Project1/frmDBRoles/Form_Load diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/Project1.vbp b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/Project1.vbp new file mode 100644 index 0000000..ac30bfc --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/Project1.vbp @@ -0,0 +1,38 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINDOWS\System32\stdole2.tlb#OLE Automation +Reference=*\G{10010001-E260-11CF-AE68-00AA004A34D5}#7.0#0#..\..\..\..\MSSQL7\Binn\Resources\1033\sqldmo.RLL#Microsoft SQLDMO Object Library +Object={BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0; TABCTL32.OCX +Form=frmAddGroups.frm +Module=Module1; Module1.bas +Form=frmNewLogin.frm +Form=frmDBRoles.frm +Form=frmManageLogins.frm +Startup="frmAddGroups" +Command32="" +Name="Project1" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionCompanyName="CMPI" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/Project1.vbw b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/Project1.vbw new file mode 100644 index 0000000..b949835 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/Project1.vbw @@ -0,0 +1,5 @@ +frmAddGroups = 21, 16, 975, 733, C, 0, 0, 0, 0, C +Module1 = 482, 182, 929, 732, C +frmNewLogin = 57, 53, 946, 689, C, 0, 0, 0, 0, C +frmDBRoles = -12, 1, 1150, 655, , 44, 58, 1069, 568, C +frmManageLogins = 69, 65, 981, 652, C, 0, 0, 0, 0, C diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/User.ICO b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/User.ICO new file mode 100644 index 0000000..148830f Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/User.ICO differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmAddGroups.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmAddGroups.frm new file mode 100644 index 0000000..1db7947 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmAddGroups.frm @@ -0,0 +1,532 @@ +VERSION 5.00 +Begin VB.Form frmAddGroups + Caption = "Add Users And Groups" + ClientHeight = 9870 + ClientLeft = 1245 + ClientTop = 2250 + ClientWidth = 12300 + LinkTopic = "Form1" + ScaleHeight = 9870 + ScaleWidth = 12300 + Begin VB.CommandButton cmdSRoleManage + Caption = "..." + Height = 2145 + Left = 630 + TabIndex = 14 + Top = 2160 + Width = 525 + End + Begin VB.CommandButton cmdMaintenance + Caption = "..." + Height = 2775 + Left = 11820 + TabIndex = 13 + Top = 2790 + Width = 405 + End + Begin VB.CommandButton cmdNewLogin + Caption = "New Login" + Height = 525 + Left = 1170 + TabIndex = 12 + Top = 8730 + Width = 2535 + End + Begin VB.ListBox lstUsers + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H00C00000& + Height = 2460 + Left = 7500 + OLEDropMode = 1 'Manual + TabIndex = 5 + Top = 6060 + Width = 4425 + End + Begin VB.ListBox lstLogins + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H00C00000& + Height = 3060 + ItemData = "frmAddGroups.frx":0000 + Left = 1170 + List = "frmAddGroups.frx":0002 + MouseIcon = "frmAddGroups.frx":0004 + OLEDragMode = 1 'Automatic + OLEDropMode = 1 'Manual + TabIndex = 4 + Top = 5550 + Width = 5325 + End + Begin VB.ListBox lstDBRoles + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H00C00000& + Height = 2760 + Left = 7470 + TabIndex = 3 + Top = 2790 + Width = 4305 + End + Begin VB.ListBox lstSRoles + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H00C00000& + Height = 2160 + Left = 1170 + TabIndex = 2 + Top = 2130 + Width = 5115 + End + Begin VB.ListBox lstDatabases + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H00C00000& + Height = 1560 + Left = 7470 + TabIndex = 1 + Top = 780 + Width = 4155 + End + Begin VB.ComboBox cboServers + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H00C00000& + Height = 420 + Left = 1170 + TabIndex = 0 + Top = 750 + Width = 4965 + End + Begin VB.Label Label6 + Caption = "Users" + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + Left = 7470 + TabIndex = 11 + Top = 5760 + Width = 3165 + End + Begin VB.Label Label5 + Caption = "Logins" + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 375 + Left = 1170 + TabIndex = 10 + Top = 5160 + Width = 2835 + End + Begin VB.Label Label4 + Caption = "Database Roles" + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + Left = 7470 + TabIndex = 9 + Top = 2460 + Width = 2955 + End + Begin VB.Label Label3 + Caption = "Server Roles" + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + Left = 1170 + TabIndex = 8 + Top = 1830 + Width = 3315 + End + Begin VB.Label Label2 + Caption = "Databases" + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + Left = 7470 + TabIndex = 7 + Top = 480 + Width = 2865 + End + Begin VB.Label Label1 + Caption = "Servers" + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 345 + Left = 1200 + TabIndex = 6 + Top = 450 + Width = 2325 + End +End +Attribute VB_Name = "frmAddGroups" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + + + +Private Function FindIfUserOwnsAnything(UserName As String, DatabaseName As String) As Integer + + +On Error GoTo err_handler +'0 means owns nothing +'1 means owns something +'2 means error + +Dim oList As SQLDMO.SQLObjectList +Dim obj As Object +Dim oUsr As SQLDMO.User + +Set oUsr = New SQLDMO.User + +FindIfUserOwnsAnything = 0 + + + + 'let's check the database owner first + + + If UCase$(oServer.Databases(DatabaseName).Owner) = UCase$(UserName) Then + FindIfUserOwnsAnything = 1 + Exit Function + End If + + 'Now the user objects + + For Each oUsr In oServer.Databases(DatabaseName).Users + If UCase$(oUsr.Login) = UCase$(UserName) Then + Set oList = oServer.Databases(DatabaseName).Users(oUsr.Name).ListOwnedObjects(SQLDMOObj_AllDatabaseUserObjects, SQLDMOObjSort_Type) + If oList.Count > 0 Then + FindIfUserOwnsAnything = 1 + Exit Function + End If + End If + Next oUsr + +Exit Function + +err_handler: + +FindIfUserOwnsAnything = 2 +Exit Function + + +End Function + +Private Sub LoadServers() + +cboServers.Clear + +For Each oGroup In SQLDMO.ServerGroups + For Each oRServer In oGroup.RegisteredServers + cboServers.AddItem oRServer.Name + Next oRServer +Next oGroup +End Sub + +Public Sub LoadDatabases() + +lstDatabases.Clear +For Each oDatabase In oServer.Databases + lstDatabases.AddItem oDatabase.Name +Next oDatabase +End Sub + +Private Sub loadDatabaseUsers(DatabaseName As String) + +lstUsers.Clear + +For Each oUser In oServer.Databases(DatabaseName).Users + lstUsers.AddItem oUser.Name & " (" & oUser.Login & ")" +Next oUser + +End Sub + +Private Sub loadDatabaseRoles(DatabaseName As String) + +lstDBRoles.Clear + +For Each oDBRole In oServer.Databases(DatabaseName).DatabaseRoles + lstDBRoles.AddItem oDBRole.Name +Next oDBRole + +End Sub + + +Private Sub loadLogins() + +lstLogins.Clear + +For Each oLogin In oServer.Logins + lstLogins.AddItem oLogin.Name +Next oLogin + +End Sub + +Private Function AddDatabaseUser(LoginName As String, DatabaseName As String) As Integer +On Error GoTo err_handler +Dim oNewUser As SQLDMO.User +Set oNewUser = New SQLDMO.User + +Dim exists As Integer + +exists = 0 + +For Each oUser In oServer.Databases(DatabaseName).Users + If UCase(oUser.Login) = UCase(LoginName) Then + exists = 1 + End If +Next oUser + +If exists = 0 Then + oNewUser.Login = LoginName + oNewUser.Name = IIf(InStr(1, LoginName, "\") > 0, Right(LoginName, Len(LoginName) - InStr(1, LoginName, "\")), LoginName) + oServer.Databases(DatabaseName).Users.Add oNewUser + MsgBox "New User " & oNewUser.Name & "(" & (oNewUser.Login) & ") added", vbInformation, "New User Added" + AddDatabaseUser = 1 + Exit Function +Else + MsgBox "User already Exists", vbInformation, "User already Exists" + AddDatabaseUser = 0 + Exit Function +End If + +Exit Function + +err_handler: +MsgBox "Error Adding User: " & Err.Description, vbCritical, "Error" +AddDatabaseUser = 0 +Exit Function + + +End Function + + +Private Sub loadSRoles() + +lstsroles.Clear + +For Each oSRole In oServer.ServerRoles + lstsroles.AddItem oSRole.Name +Next oSRole + +End Sub + +Private Sub cboServers_Click() + +Set oServer = New SQLDMO.SQLServer + +oServer.LoginSecure = True +oServer.Connect cboServers.Text + +LoadDatabases +loadLogins +loadSRoles + +End Sub + + + +Private Sub cmdMaintenance_Click() +If lstDatabases.SelCount > 0 Then + frmDBRoles.Visible = True +End If +End Sub + +Private Sub cmdNewLogin_Click() +frmNewLogin.Visible = True +End Sub + +Private Sub cmdSRoleManage_Click() +frmManageLogins.Visible = True +End Sub + +Private Sub Form_Load() +Me.Left = (Screen.Width - Me.Width) \ 2 +Me.Top = (Screen.Height - Me.Height) \ 2 + +LoadServers +End Sub + +Private Sub lstdatabases_Click() +loadDatabaseRoles lstDatabases.Text +loadDatabaseUsers lstDatabases.Text +End Sub + +Private Function ShowIfWeCanDeleteLogin(LoginName As String) As Integer + +Dim CanWe As Integer +Dim oDatabase As SQLDMO.Database +Dim oList As SQLDMO.SQLObjectList +Dim obj As Object +Dim oUsr As SQLDMO.User + +CanWe = 1 + + + + 'let's check the database owner first + + For Each oDatabase In oServer.Databases + If UCase$(oDatabase.Owner) = UCase$(LoginName) Then + CanWe = 0 + End If + + 'Now the user objects + + For Each oUsr In oDatabase.Users + If UCase$(oUsr.Login) = UCase$(LoginName) Then + Set oList = oServer.Databases(oDatabase.Name).Users(oUsr.Name).ListOwnedObjects(SQLDMOObj_AllDatabaseUserObjects, SQLDMOObjSort_Type) + If oList.Count > 0 Then + CanWe = 0 + End If + End If + Next oUsr + Next oDatabase + + ShowIfWeCanDeleteLogin = CanWe + + + + +End Function + +Private Sub lstLogins_DblClick() + +If MsgBox("Delete Login " & lstLogins.Text & "?", vbQuestion + vbYesNo, "Remove Login") = vbNo Then + Exit Sub +Else + If ShowIfWeCanDeleteLogin(lstLogins.Text) = 1 Then + oServer.Logins.Remove lstLogins.Text + lstLogins.RemoveItem lstLogins.ListIndex + Else + MsgBox "Login Owns objects within 1 or more databases", vbInformation, "Removal Aborted" + End If +End If + +End Sub + +Private Sub lstLogins_OLESetData(Data As DataObject, DataFormat As Integer) +Data = lstLogins.Text +End Sub + +Private Sub lstUsers_DblClick() + + +Dim NameToCheck As String + +NameToCheck = Mid(lstUsers.Text, 1, InStr(1, lstUsers.Text, "(") - 2) + +If FindIfUserOwnsAnything(oServer.Databases(lstDatabases.Text).Users(NameToCheck).Login, lstDatabases.Text) = 0 Then + 'oUsr.Name = Mid(lstUsers.Text, 1, InStr(1, lstUsers.Text, "(") - 2) + lstUsers.RemoveItem lstUsers.ListIndex + oServer.Databases(lstDatabases.Text).Users(NameToCheck).Remove + MsgBox "User Removed", vbInformation, "User Removed" +ElseIf FindIfUserOwnsAnything(oServer.Databases(lstDatabases.Text).Users(NameToCheck).Login, lstDatabases.Text) = 1 Then + MsgBox "This User Owns Objects", vbInformation, "Cannot Remove Login" +ElseIf FindIfUserOwnsAnything(oServer.Databases(lstDatabases.Text).Users(NameToCheck).Login, lstDatabases.Text) = 2 Then + MsgBox "An Error Occured" +End If + + +End Sub + +Private Sub lstUsers_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) +Dim UserToAdd As String +UserToAdd = IIf(InStr(1, Data.GetData(1), "\") > 0, Right(Data.GetData(1), Len(Data.GetData(1)) - InStr(1, Data.GetData(1), "\")), Data.GetData(1)) + " (" + Data.GetData(1) + ")" + + + + If AddDatabaseUser(Data.GetData(1), lstDatabases.Text) = 1 Then + lstUsers.AddItem UserToAdd + End If + + +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmAddGroups.frx b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmAddGroups.frx new file mode 100644 index 0000000..cc47928 Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmAddGroups.frx differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmDBRoles.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmDBRoles.frm new file mode 100644 index 0000000..2ad7ab0 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmDBRoles.frm @@ -0,0 +1,360 @@ +VERSION 5.00 +Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX" +Begin VB.Form frmDBRoles + Caption = "Roles" + ClientHeight = 5955 + ClientLeft = 3300 + ClientTop = 2595 + ClientWidth = 7125 + LinkTopic = "Form1" + ScaleHeight = 5955 + ScaleWidth = 7125 + Begin TabDlg.SSTab SSTab1 + Height = 6075 + Left = 0 + TabIndex = 0 + Top = 0 + Width = 7185 + _ExtentX = 12674 + _ExtentY = 10716 + _Version = 393216 + Tabs = 2 + Tab = 1 + TabHeight = 520 + TabCaption(0) = "Add To Role" + TabPicture(0) = "frmDBRoles.frx":0000 + Tab(0).ControlEnabled= 0 'False + Tab(0).Control(0)= "cmdExit" + Tab(0).Control(1)= "cmdValidate" + Tab(0).Control(2)= "lstRoles" + Tab(0).ControlCount= 3 + TabCaption(1) = "New Role" + TabPicture(1) = "frmDBRoles.frx":001C + Tab(1).ControlEnabled= -1 'True + Tab(1).Control(0)= "Label1" + Tab(1).Control(0).Enabled= 0 'False + Tab(1).Control(1)= "Label2" + Tab(1).Control(1).Enabled= 0 'False + Tab(1).Control(2)= "txtRoleName" + Tab(1).Control(2).Enabled= 0 'False + Tab(1).Control(3)= "optApp" + Tab(1).Control(3).Enabled= 0 'False + Tab(1).Control(4)= "optNormal" + Tab(1).Control(4).Enabled= 0 'False + Tab(1).Control(5)= "txtPassword" + Tab(1).Control(5).Enabled= 0 'False + Tab(1).Control(6)= "cmdAdd" + Tab(1).Control(6).Enabled= 0 'False + Tab(1).Control(7)= "cmdClose" + Tab(1).Control(7).Enabled= 0 'False + Tab(1).ControlCount= 8 + Begin VB.CommandButton cmdExit + Caption = "Exit" + Height = 615 + Left = -69630 + TabIndex = 11 + Top = 5100 + Width = 1515 + End + Begin VB.CommandButton cmdValidate + Caption = "Add" + Height = 615 + Left = -71430 + TabIndex = 10 + Top = 5100 + Width = 1515 + End + Begin VB.ListBox lstRoles + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H000000FF& + Height = 3690 + Left = -74670 + Style = 1 'Checkbox + TabIndex = 9 + Top = 930 + Width = 6525 + End + Begin VB.CommandButton cmdClose + Caption = "Close" + Height = 645 + Left = 5340 + TabIndex = 8 + Top = 5010 + Width = 1485 + End + Begin VB.CommandButton cmdAdd + Caption = "Add" + Height = 645 + Left = 3360 + TabIndex = 7 + Top = 5010 + Width = 1485 + End + Begin VB.TextBox txtPassword + Height = 345 + Left = 630 + TabIndex = 5 + Top = 3600 + Width = 5025 + End + Begin VB.OptionButton optNormal + Caption = "Standard" + Height = 435 + Left = 540 + TabIndex = 4 + Top = 2340 + Width = 3765 + End + Begin VB.OptionButton optApp + Caption = "Application Role" + Height = 375 + Left = 540 + TabIndex = 3 + Top = 2850 + Width = 3465 + End + Begin VB.TextBox txtRoleName + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 420 + Left = 510 + TabIndex = 1 + Top = 1380 + Width = 5835 + End + Begin VB.Label Label2 + Caption = "Password" + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 315 + Left = 600 + TabIndex = 6 + Top = 3330 + Width = 3405 + End + Begin VB.Label Label1 + Caption = "Role Name" + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 510 + TabIndex = 2 + Top = 1080 + Width = 4485 + End + End +End +Attribute VB_Name = "frmDBRoles" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + + +Private Sub cmdAdd_Click() +Dim i As Integer +If txtRoleName.Text <> "" Then + If optNormal.Value = True Then + AddDatabaseRole txtRoleName.Text, 1, frmAddGroups.lstDatabases.Text + ClearUp + Else + AddDatabaseRole txtRoleName.Text, 0, frmAddGroups.lstDatabases.Text, IIf(txtPassword.Text <> "", txtPassword.Text, "Password") + ClearUp + End If + + showAllDbroles frmAddGroups.lstDatabases.Text + +For i = 0 To lstRoles.ListCount - 1 + If ShowRoleUserMemberOf(Left(frmAddGroups.lstUsers.Text, InStr(1, frmAddGroups.lstUsers.Text, "(") - 2), frmAddGroups.lstDatabases.Text, lstRoles.List(i)) = True Then + lstRoles.Selected(i) = True + End If +Next i + +End If + + + +End Sub + +Private Sub ClearUp() +txtPassword.Text = "" +txtRoleName.Text = "" +End Sub + +Private Sub cmdClose_Click() +Unload Me +End Sub + +Private Sub cmdExit_Click() +Unload Me +End Sub + +Private Sub showAllDbroles(DatabaseName As String) +lstRoles.Clear +For Each oDBRole In oServer.Databases(DatabaseName).DatabaseRoles + If oDBRole.AppRole = False Then + lstRoles.AddItem oDBRole.Name + End If + +Next oDBRole +End Sub + +Private Sub cmdValidate_Click() + + +Dim j As Integer +Dim i As Integer + +For j = 0 To lstRoles.ListCount - 1 + +Select Case ReturnValuesofMembership(Left(frmAddGroups.lstUsers.Text, InStr(1, frmAddGroups.lstUsers.Text, "(") - 2), frmAddGroups.lstDatabases.Text, lstRoles.List(j), lstRoles.Selected(j)) + + Case NEEDS_ADDING + oServer.Databases(frmAddGroups.lstDatabases.Text).DatabaseRoles(lstRoles.List(j)).AddMember Left(frmAddGroups.lstUsers.Text, InStr(1, frmAddGroups.lstUsers.Text, "(") - 2) + + Case NEEDS_DELETING + oServer.Databases(frmAddGroups.lstDatabases.Text).DatabaseRoles(lstRoles.List(j)).DropMember Left(frmAddGroups.lstUsers.Text, InStr(1, frmAddGroups.lstUsers.Text, "(") - 2) + +End Select + +Next j + +End Sub + +Private Sub Form_Load() +lstRoles.Clear +Dim i As Integer +showAllDbroles frmAddGroups.lstDatabases.Text +optNormal.Value = True + +For i = 0 To lstRoles.ListCount - 1 + If ShowRoleUserMemberOf(Left(frmAddGroups.lstUsers.Text, InStr(1, frmAddGroups.lstUsers.Text, "(") - 2), frmAddGroups.lstDatabases.Text, lstRoles.List(i)) = True Then + lstRoles.Selected(i) = True + End If +Next i + + + +End Sub + +Private Sub AddDatabaseRole(rolename As String, RoleType As Integer, DatabaseName As String, Optional Password As String) +'1 = standard +'0 = app + +Dim exists As Integer +Dim onewdbrole As SQLDMO.DatabaseRole +Set onewdbrole = New SQLDMO.DatabaseRole +exists = 0 + +For Each oDBRole In oServer.Databases(DatabaseName).DatabaseRoles + If UCase(oDBRole.Name) = UCase(rolename) Then + exists = 1 + MsgBox "Role already Exists", vbInformation, "Exists" + Exit Sub + End If +Next oDBRole + +If exists = 0 Then + If RoleType = 1 Then + onewdbrole.Name = rolename + onewdbrole.AppRole = False + oServer.Databases(DatabaseName).DatabaseRoles.Add onewdbrole + ElseIf RoleType = 0 Then + onewdbrole.Name = rolename + onewdbrole.AppRole = True + onewdbrole.Password = Password + oServer.Databases(DatabaseName).DatabaseRoles.Add onewdbrole + End If +End If + + +End Sub + +Private Function ShowRoleUserMemberOf(UserName As String, DatabaseName As String, DBRole As String) As Boolean +Dim i As Integer +Dim j As Integer +ShowRoleUserMemberOf = False + + + +Dim oQryresults As SQLDMO.QueryResults + +Set oQryresults = oServer.Databases(DatabaseName).DatabaseRoles(DBRole).EnumDatabaseRoleMember + +For i = 1 To oQryresults.Rows + If oQryresults.GetColumnString(i, 1) = UserName Then + ShowRoleUserMemberOf = True + End If + +Next i + +End Function + + +Public Function ReturnValuesofMembership(strUserName As String, strDatabaseName As String, strRoleName As String, booChecked As Boolean) As Integer + +Dim i As Integer +Dim booInList As Boolean + + +Dim oQList As SQLDMO.QueryResults + +Set oQList = oServer.Databases(strDatabaseName).DatabaseRoles(strRoleName).EnumDatabaseRoleMember + + + booInList = False 'assume we will not find the name + + For i = 1 To oQList.Rows + If UCase(Trim(oQList.GetColumnString(i, 1))) = UCase(Trim(strUserName)) Then + booInList = True + Exit For + End If + Next i + + If booInList = True And booChecked = True Then + 'in the list and checkbox ticked = still a member + ReturnValuesofMembership = IS_MEMBER + End If + 'in the list and checkbox not ticked = needs removing + If booInList = True And booChecked = False Then + ReturnValuesofMembership = NEEDS_DELETING + End If + + If booInList = False And booChecked = True Then + 'not in the list and checkbox ticked = needs adding + ReturnValuesofMembership = NEEDS_ADDING + End If + +End Function + + diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmDBRoles.frx b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmDBRoles.frx new file mode 100644 index 0000000..443150d Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmDBRoles.frx differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmManageLogins.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmManageLogins.frm new file mode 100644 index 0000000..86dc8ba --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmManageLogins.frm @@ -0,0 +1,151 @@ +VERSION 5.00 +Begin VB.Form frmManageLogins + Caption = "Manage Logins" + ClientHeight = 5610 + ClientLeft = 4335 + ClientTop = 2595 + ClientWidth = 6510 + LinkTopic = "Form1" + ScaleHeight = 5610 + ScaleWidth = 6510 + Begin VB.CommandButton cmdClose + Caption = "Close" + Height = 495 + Left = 4770 + TabIndex = 2 + Top = 4980 + Width = 1305 + End + Begin VB.CommandButton cmdSubmit + Caption = "Submit" + Height = 495 + Left = 2940 + TabIndex = 1 + Top = 4980 + Width = 1305 + End + Begin VB.ListBox lstsroles + BeginProperty Font + Name = "MS Sans Serif" + Size = 18 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 4245 + Left = 480 + Style = 1 'Checkbox + TabIndex = 0 + Top = 570 + Width = 5625 + End +End +Attribute VB_Name = "frmManageLogins" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit +Private Sub populateRoles() + +lstsroles.Clear + +For Each oSRole In oServer.ServerRoles + lstsroles.AddItem oSRole.Name +Next oSRole +End Sub + +Private Function ShowSRoleLoginMemberOf(LoginName As String, SRole As String) As Boolean +Dim i As Integer + +ShowSRoleLoginMemberOf = False + + +Dim oQryresults As SQLDMO.QueryResults + +Set oQryresults = oServer.ServerRoles(SRole).EnumServerRoleMember + +For i = 1 To oQryresults.Rows + If oQryresults.GetColumnString(i, 1) = LoginName Then + ShowSRoleLoginMemberOf = True + End If + +Next i + +End Function + + +Private Sub cmdClose_Click() +Unload Me +End Sub + +Private Sub cmdSubmit_Click() +Dim j As Integer +Dim i As Integer + +For j = 0 To lstsroles.ListCount - 1 + +Select Case ReturnValuesofSMembership(frmAddGroups.lstLogins.Text, lstsroles.List(j), lstsroles.Selected(j)) + + Case NEEDS_ADDING + oServer.ServerRoles(lstsroles.List(j)).AddMember frmAddGroups.lstLogins.Text + + Case NEEDS_DELETING + oServer.ServerRoles(lstsroles.List(j)).DropMember frmAddGroups.lstLogins.Text + +End Select + +Next j + +End Sub + +Private Sub Form_Load() +lstsroles.Clear +Dim i As Integer +populateRoles + +For i = 0 To lstsroles.ListCount - 1 + If ShowSRoleLoginMemberOf(frmAddGroups.lstLogins.Text, lstsroles.List(i)) = True Then + lstsroles.Selected(i) = True + End If +Next i +End Sub + +Public Function ReturnValuesofSMembership(strLoginName As String, strSRoleName As String, booChecked As Boolean) As Integer + +Dim i As Integer +Dim booInList As Boolean + + +Dim oQList As SQLDMO.QueryResults + +Set oQList = oServer.ServerRoles(strSRoleName).EnumServerRoleMember + + + booInList = False 'assume we will not find the name + + For i = 1 To oQList.Rows + If UCase(Trim(oQList.GetColumnString(i, 1))) = UCase(Trim(strLoginName)) Then + booInList = True + Exit For + End If + Next i + + If booInList = True And booChecked = True Then + 'in the list and checkbox ticked = still a member + ReturnValuesofSMembership = IS_MEMBER + End If + 'in the list and checkbox not ticked = needs removing + If booInList = True And booChecked = False Then + ReturnValuesofSMembership = NEEDS_DELETING + End If + + If booInList = False And booChecked = True Then + 'not in the list and checkbox ticked = needs adding + ReturnValuesofSMembership = NEEDS_ADDING + End If + +End Function + diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmNewLogin.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmNewLogin.frm new file mode 100644 index 0000000..ccb3f96 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmNewLogin.frm @@ -0,0 +1,178 @@ +VERSION 5.00 +Begin VB.Form frmNewLogin + Caption = "New Login" + ClientHeight = 3945 + ClientLeft = 4215 + ClientTop = 3720 + ClientWidth = 5625 + LinkTopic = "Form1" + ScaleHeight = 3945 + ScaleWidth = 5625 + Begin VB.CommandButton cmdClose + Caption = "Close" + Height = 525 + Left = 4230 + TabIndex = 7 + Top = 3360 + Width = 1335 + End + Begin VB.CommandButton cmdAdd + Caption = "Add" + Height = 525 + Left = 2700 + TabIndex = 6 + Top = 3390 + Width = 1335 + End + Begin VB.TextBox txtUserName + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 420 + Left = 270 + TabIndex = 3 + Top = 960 + Width = 4845 + End + Begin VB.TextBox txtPassword + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H000000FF& + Height = 420 + IMEMode = 3 'DISABLE + Left = 240 + PasswordChar = "?" + TabIndex = 2 + Top = 2550 + Width = 4785 + End + Begin VB.OptionButton optNT + Caption = "NT" + Height = 345 + Left = 240 + TabIndex = 1 + Top = 1860 + Width = 2955 + End + Begin VB.OptionButton optSS + Caption = "SQL Server" + Height = 345 + Left = 240 + TabIndex = 0 + Top = 1500 + Width = 2925 + End + Begin VB.Label Label1 + Caption = "User Name" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 270 + TabIndex = 5 + Top = 750 + Width = 3975 + End + Begin VB.Label Label2 + Caption = "Password" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 225 + Left = 240 + TabIndex = 4 + Top = 2340 + Width = 3285 + End +End +Attribute VB_Name = "frmNewLogin" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmdAdd_Click() + +If optNT.Value = True And txtUserName.Text <> "" Then + AddnewUser txtUserName, 1 + frmAddGroups.lstLogins.AddItem txtUserName + ClearDown + + +ElseIf optSS.Value = True And txtUserName.Text <> "" Then + AddnewUser txtUserName, 0, IIf(txtPassword.Text <> "", txtPassword.Text, "password") + frmAddGroups.lstLogins.AddItem txtUserName + ClearDown + +End If + + +End Sub + +Private Sub cmdClose_Click() +Unload Me +End Sub + +Private Sub AddnewUser(UserName As String, NTSQL As Integer, Optional Password As String) +Dim exists As Integer +Dim oNewLogin As SQLDMO.Login +Set oNewLogin = New SQLDMO.Login +exists = 0 + +For Each oLogin In oServer.Logins + If UCase(oLogin.Name) = UCase(UserName) Then + exists = 1 + MsgBox "Login already exists", vbInformation, "Login already Exists" + Exit Sub + End If +Next oLogin + + If exists = 0 Then + If NTSQL = 1 Then + oNewLogin.Name = UserName + oNewLogin.Type = SQLDMOLogin_NTUser + Else + oNewLogin.Name = UserName + oNewLogin.Type = SQLDMOLogin_Standard + oNewLogin.SetPassword "", Password + End If +End If + + + +oServer.Logins.Add oNewLogin + + + +End Sub + +Private Sub ClearDown() +txtPassword.Text = "" +txtUserName.Text = "" +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmNewLogin.frx b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmNewLogin.frx new file mode 100644 index 0000000..4d38e06 Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/AddUserApp/frmNewLogin.frx differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/Form1.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/Form1.frm new file mode 100644 index 0000000..d710c4b --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/Form1.frm @@ -0,0 +1,260 @@ +VERSION 5.00 +Begin VB.Form frmView + Caption = "View" + ClientHeight = 6180 + ClientLeft = 2895 + ClientTop = 5880 + ClientWidth = 11610 + LinkTopic = "Form1" + ScaleHeight = 6180 + ScaleWidth = 11610 + Begin VB.CommandButton cmdUpdate + Caption = "Update" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 465 + Left = 7950 + TabIndex = 7 + Top = 5430 + Width = 1515 + End + Begin VB.CheckBox chkInsert + Caption = "INSERT" + Height = 345 + Left = 7110 + TabIndex = 6 + Top = 2451 + Width = 3915 + End + Begin VB.CheckBox chkDelete + Caption = "DELETE" + Height = 345 + Left = 7110 + TabIndex = 5 + Top = 1874 + Width = 3915 + End + Begin VB.CheckBox chkUpdate + Caption = "UPDATE" + Height = 345 + Left = 7110 + TabIndex = 4 + Top = 1297 + Width = 3915 + End + Begin VB.CheckBox chkSelect + Caption = "SELECT" + Height = 345 + Left = 7110 + TabIndex = 3 + Top = 720 + Width = 3915 + End + Begin VB.ListBox lstTables + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H00FF0000& + Height = 4260 + Left = 150 + TabIndex = 2 + Top = 690 + Width = 6375 + End + Begin VB.CommandButton cmdClose + Caption = "Close" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 465 + Left = 9630 + TabIndex = 0 + Top = 5430 + Width = 1515 + End + Begin VB.Label Label1 + Caption = "Tables" + BeginProperty Font + Name = "MS Sans Serif" + Size = 13.5 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 315 + Left = 150 + TabIndex = 1 + Top = 330 + Width = 3135 + End +End +Attribute VB_Name = "frmView" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub ValidatePermissions(DatabaseName As String, tableName As String, UserName As String) +DoEvents + + + +Dim i As Integer + + +Set oList = oServer.Databases(DatabaseName).Tables(tableName).ListUserPermissions(UserName) + +For Each objPermission In oList + + Select Case objPermission.PrivilegeTypeName + + Case "Select" + chkSelect.Value = vbChecked + + Case "Insert" + chkInsert.Value = vbChecked + + Case "Update" + chkUpdate.Value = vbChecked + + Case "Delete" + chkDelete.Value = vbChecked + +End Select + +Next objPermission + +End Sub + +Sub AlterPermissionOrNot(DatabaseName As String, tableName As String, UserName As String) + +Dim Sselect As Integer +Dim Iinsert As Integer +Dim Uupdate As Integer +Dim Ddelete As Integer + + +Sselect = 0 +Ddelete = 0 +Iinsert = 0 +Uupdate = 0 + + + +For Each objPermission In oList + +If objPermission.PrivilegeTypeName = "Select" Then + Sselect = 1 +End If + +If objPermission.PrivilegeTypeName = "Update" Then + Uupdate = 1 +End If + +If objPermission.PrivilegeTypeName = "Delete" Then + Ddelete = 1 +End If + +If objPermission.PrivilegeTypeName = "Insert" Then + Iinsert = 1 +End If + +Next objPermission + + +If Sselect = 1 And chkSelect.Value = vbUnchecked Then + oServer.Databases(DatabaseName).Tables(tableName).Revoke SQLDMOPriv_Select, UserName +ElseIf Sselect = 0 And chkSelect.Value = vbChecked Then + oServer.Databases(DatabaseName).Tables(tableName).Grant SQLDMOPriv_Select, UserName +End If + +If Uupdate = 1 And chkUpdate.Value = vbUnchecked Then + oServer.Databases(DatabaseName).Tables(tableName).Revoke SQLDMOPriv_Update, UserName +ElseIf Uupdate = 0 And chkUpdate.Value = vbChecked Then + oServer.Databases(DatabaseName).Tables(tableName).Grant SQLDMOPriv_Update, UserName +End If + +If Iinsert = 1 And chkInsert.Value = vbUnchecked Then + oServer.Databases(DatabaseName).Tables(tableName).Revoke SQLDMOPriv_Insert, UserName +ElseIf Iinsert = 0 And chkInsert.Value = vbChecked Then + oServer.Databases(DatabaseName).Tables(tableName).Grant SQLDMOPriv_Insert, UserName +End If + +If Ddelete = 1 And chkDelete.Value = vbUnchecked Then + oServer.Databases(DatabaseName).Tables(tableName).Revoke SQLDMOPriv_Delete, UserName +ElseIf Ddelete = 0 And chkDelete.Value = vbChecked Then + oServer.Databases(DatabaseName).Tables(tableName).Grant SQLDMOPriv_Delete, UserName +End If + + + + + + + + + + + + + +End Sub + + +Private Sub ClearBoxes() +chkInsert.Value = vbUnchecked +chkSelect.Value = vbUnchecked +chkUpdate.Value = vbUnchecked +chkDelete.Value = vbUnchecked + +End Sub + +Private Sub cmdClose_Click() +Me.Visible = False +End Sub +Private Sub PopulateTables() + +For Each oTable In oServer.Databases(frmpermissions.cboDatabases.Text).Tables + lstTables.AddItem oTable.Name +Next oTable + +End Sub + + +Private Sub cmdUpdate_Click() +AlterPermissionOrNot frmpermissions.cboDatabases.Text, lstTables.Text, frmpermissions.lstUsers.Text +End Sub + +Private Sub Form_Load() + +PopulateTables +End Sub + + +Private Sub lstTables_Click() +ClearBoxes +ValidatePermissions frmpermissions.cboDatabases.Text, lstTables.Text, frmpermissions.lstUsers.Text + +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/MSSCCPRJ.SCC b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/MSSCCPRJ.SCC new file mode 100644 index 0000000..1d6a7fa --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/MSSCCPRJ.SCC @@ -0,0 +1,5 @@ +[SCC] +SCC=This is a source code control file +[Project1.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/Module1.bas b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/Module1.bas new file mode 100644 index 0000000..543af64 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/Module1.bas @@ -0,0 +1,12 @@ +Attribute VB_Name = "Module1" +Option Explicit + +Public oGroup As SQLDMO.ServerGroup +Public oServer As SQLDMO.SQLServer +Public oRServer As SQLDMO.RegisteredServer +Public oDatabase As SQLDMO.Database +Public oUser As SQLDMO.User +Public oTable As SQLDMO.Table +Public oList As SQLDMO.SQLObjectList +Public objPermission As SQLDMO.Permission + diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/Project1.vbp b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/Project1.vbp new file mode 100644 index 0000000..1a029de --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/Project1.vbp @@ -0,0 +1,36 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\stdole2.tlb#OLE Automation +Reference=*\G{10010001-E260-11CF-AE68-00AA004A34D5}#7.0#0#C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll#Microsoft SQLDMO Object Library +Object={5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0; MSFLXGRD.OCX +Form=frmpermissions.frm +Form=Form1.frm +Module=Module1; Module1.bas +Startup="frmpermissions" +Command32="" +Name="Project1" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionCompanyName="CMPI" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/Project1.vbw b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/Project1.vbw new file mode 100644 index 0000000..12669d0 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/Project1.vbw @@ -0,0 +1,3 @@ +frmpermissions = 269, 288, 1083, 952, C, 0, 0, 0, 0, C +frmView = 224, 179, 1215, 862, C, 0, 0, 0, 0, C +Module1 = 424, 181, 871, 731, C diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/frmpermissions.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/frmpermissions.frm new file mode 100644 index 0000000..b133d95 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/frmpermissions.frm @@ -0,0 +1,190 @@ +VERSION 5.00 +Begin VB.Form frmpermissions + Caption = "Permissions" + ClientHeight = 7065 + ClientLeft = 3375 + ClientTop = 2625 + ClientWidth = 7365 + LinkTopic = "Form1" + ScaleHeight = 7065 + ScaleWidth = 7365 + Begin VB.CommandButton Command1 + Caption = "CLOSE" + BeginProperty Font + Name = "MS Sans Serif" + Size = 24 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 3075 + Left = 6810 + TabIndex = 7 + Top = 3840 + Width = 465 + End + Begin VB.TextBox Text1 + Alignment = 2 'Center + Appearance = 0 'Flat + BackColor = &H8000000F& + BorderStyle = 0 'None + BeginProperty Font + Name = "MS Sans Serif" + Size = 24 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 495 + Left = 240 + MultiLine = -1 'True + TabIndex = 6 + Text = "frmpermissions.frx":0000 + Top = 240 + Width = 6975 + End + Begin VB.ComboBox cboDatabases + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 420 + Left = 660 + TabIndex = 2 + Top = 1920 + Width = 6105 + End + Begin VB.ListBox lstUsers + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H000000FF& + Height = 3960 + Left = 660 + TabIndex = 1 + Top = 2910 + Width = 5985 + End + Begin VB.ComboBox cboServer + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 420 + Left = 660 + TabIndex = 0 + Top = 1080 + Width = 6075 + End + Begin VB.Label Label3 + Caption = "Users" + Height = 285 + Left = 660 + TabIndex = 5 + Top = 2670 + Width = 2925 + End + Begin VB.Label Label2 + Caption = "Databases" + Height = 225 + Left = 660 + TabIndex = 4 + Top = 1170 + Width = 2475 + End + Begin VB.Label Label1 + Caption = "Servers" + Height = 315 + Left = 660 + TabIndex = 3 + Top = 810 + Width = 3915 + End +End +Attribute VB_Name = "frmpermissions" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub PopulateServers() +cboServer.Clear + +For Each oGroup In SQLDMO.ServerGroups + For Each oRServer In oGroup.RegisteredServers + cboServer.AddItem oRServer.Name + Next oRServer +Next oGroup + +End Sub + +Private Sub PopulateDatabases(ServerName As String) +cboDatabases.Clear + +If ServerName <> "" Then + Set oServer = New SQLDMO.SQLServer + oServer.LoginSecure = True + oServer.Connect ServerName + For Each oDatabase In oServer.Databases + cboDatabases.AddItem oDatabase.Name + Next oDatabase + +End If + +End Sub + + +Private Sub PopulateUsers(ServerName As String, DatabaseName As String) +lstUsers.Clear + +If ServerName <> "" And DatabaseName <> "" Then + + For Each oUser In oServer.Databases(DatabaseName).Users + lstUsers.AddItem oUser.Name + Next oUser +End If + + +End Sub + +Private Sub cboDatabases_Click() +PopulateUsers cboServer.Text, cboDatabases.Text +End Sub + +Private Sub cboServer_Click() +PopulateDatabases (cboServer.Text) +End Sub + +Private Sub Command1_Click() +Unload Me +Application.Quit +End Sub + +Private Sub Form_Load() +PopulateServers +End Sub + +Private Sub lstUsers_Click() +frmView.Visible = True +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/frmpermissions.frx b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/frmpermissions.frx new file mode 100644 index 0000000..9dfc2e2 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Permissions And Users/Code/Permissions/frmpermissions.frx @@ -0,0 +1 @@ + Permissions \ No newline at end of file diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/MSSCCPRJ.SCC b/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/MSSCCPRJ.SCC new file mode 100644 index 0000000..4a2668d --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/MSSCCPRJ.SCC @@ -0,0 +1,5 @@ +[SCC] +SCC=This is a source code control file +[replication.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/frmReplicate.frm b/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/frmReplicate.frm new file mode 100644 index 0000000..c0a5b32 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/frmReplicate.frm @@ -0,0 +1,206 @@ +VERSION 5.00 +Begin VB.Form frmReplicate + Caption = "Replicate!" + ClientHeight = 4065 + ClientLeft = 4740 + ClientTop = 4350 + ClientWidth = 3765 + LinkTopic = "Form1" + ScaleHeight = 4065 + ScaleWidth = 3765 + Begin VB.CommandButton cmdSubscriber + Caption = "Install Subscriber" + Height = 375 + Left = 120 + TabIndex = 5 + Top = 1260 + Width = 1455 + End + Begin VB.CommandButton cmdExit + Caption = "E&xit" + Height = 375 + Left = 1680 + TabIndex = 4 + Top = 3120 + Width = 1215 + End + Begin VB.CommandButton cmdInstallMerge + Caption = "Install Merge" + Height = 375 + Left = 120 + TabIndex = 3 + Top = 720 + Width = 1455 + End + Begin VB.CommandButton cmdUninstall + Caption = "&Uninstall Repl" + Height = 375 + Left = 120 + TabIndex = 2 + Top = 3120 + Width = 1455 + End + Begin VB.CommandButton cmdGo + Caption = "Install Distributor" + Height = 375 + Left = 120 + TabIndex = 0 + Top = 240 + Width = 1455 + End + Begin VB.Label lblStatus + Caption = "Status" + Height = 255 + Left = 120 + TabIndex = 1 + Top = 3720 + Width = 3495 + End +End +Attribute VB_Name = "frmReplicate" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit +Dim bConnected As Boolean + +Dim objSrv1 As New SQLDMO.SQLServer +Dim objSrv2 As New SQLDMO.SQLServer + +Dim objReplication As New SQLDMO.Replication +Dim objDistribDB As New SQLDMO.DistributionDatabase +Dim objPublisher As New SQLDMO.DistributionPublisher +Dim oPub As SQLDMO.Publisher +Dim mpsMergesubscription As SQLDMO.MergeSubscription +Dim subSubscriber As SQLDMO.RegisteredSubscriber +Dim bMergeExists As Boolean + + + + +Private Sub cmdGo_Click() + + 'first let's check we have a publisher + + bConnected = False + bMergeExists = False + + 'log on to the server + + With objSrv1 + .LoginSecure = True + .Connect "ALLAN" ' The publisher and distributor + End With + + Debug.Print "Connected to Server Allan" + + + bConnected = True + + 'if the distributor is already available then + 'we can skip installing it. And vice versa + + If objSrv1.Replication.Distributor.DistributorAvailable = False Then + objDistribDB.Name = "distribution" ' set the distribution database name + objSrv1.Replication.Distributor.DistributionDatabases.Add objDistribDB ' add the distribution database to the collection + With objSrv1.Replication.Distributor + .DistributionServer = objSrv1.TrueName ' set the distribution server to the true name of the local server + .Install + End With + End If + + Debug.Print "Distributor Done" + + ' Now let's add a publisher + + If objSrv1.Replication.Distributor.IsDistributionPublisher = False Then + + objPublisher.Name = objSrv1.TrueName ' set the publisher to be the local server + objPublisher.DistributionDatabase = "distribution" 'Which database are we going to use for distribution + objPublisher.DistributionWorkingDirectory = App.Path & "\ReplWorkingDir" 'Set the working directory + objSrv1.Replication.Distributor.DistributionPublishers.Add objPublisher + objPublisher.ThirdParty = True + + End If + + Debug.Print "Publisher Done" + + 'once we've added the publisher and the distributor + 'we need to create a publication + + Dim objReplicationDB As SQLDMO.ReplicationDatabase + Dim objMergeReplication As New SQLDMO.MergePublication + Dim objMergeArticle1 As New SQLDMO.MergeArticle + + ' shows databases available for replication + 'For Each objReplicationDB In objSrv1.Replication.ReplicationDatabases + 'Debug.Print objReplicationDB.Name + 'Next + + If objSrv1.Replication.ReplicationDatabases("Northwind").EnableMergePublishing = False Then + objSrv1.Replication.ReplicationDatabases("Northwind").EnableMergePublishing = True + End If + + Debug.Print "Merge Publishing Enabled" + + ' Add a merge publication + + For Each objMergeReplication In objSrv1.Replication.ReplicationDatabases("Northwind").MergePublications + If objMergeReplication.Name = "NewMergeReplication" Then + bMergeExists = True + End If + Next + + Debug.Print "Check to see if publication exists Done" + + If bMergeExists = False Then + objMergeReplication.Name = "NewMergeReplication" + objMergeReplication.PublicationAttributes = SQLDMOPubAttrib_AllowPull + SQLDMOPubAttrib_AllowPush + objSrv1.Replication.ReplicationDatabases("Northwind").MergePublications.Add objMergeReplication + + 'add an article + objMergeArticle1.Name = "Customers" + objMergeArticle1.SourceObjectName = "Customers" + objMergeArticle1.SourceObjectOwner = "dbo" + objMergeArticle1.ColumnTracking = True ' set columntracking on to improve accuracy + objMergeArticle1.Status = SQLDMOArtStat_Active + objMergeReplication.MergeArticles.Add objMergeArticle1 + + End If + + Debug.Print "Publication added and Article added to publication" + + + Set subSubscriber = New SQLDMO.RegisteredSubscriber + + subSubscriber.Name = "ALLAN\Am3" + + + objSrv1.Replication.Publisher.RegisteredSubscribers.Add subSubscriber + + Debug.Print "Subscriber Added" + + + + + Set mpsMergesubscription = New SQLDMO.MergeSubscription + + With mpsMergesubscription + + .Subscriber = "ALLAN\Am3" + .SubscriptionDB = "Northwind" + '.MergeSchedule = 'Add a schedule object here + + + End With + + + objSrv1.Replication.ReplicationDatabases("Northwind").MergePublications("NewMergeReplication").MergeSubscriptions.Add mpsMergesubscription + + + + + + +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/replication.csi b/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/replication.csi new file mode 100644 index 0000000..e949e13 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/replication.csi @@ -0,0 +1,6 @@ +[History] +B0=Replication/frmReplicate/cmdGo_Click +B1=Replication/frmReplicate +B2=Replication/frmReplicate/Form_Load +B3=Replication/frmReplicate/cmdSubscriber_Click +B4=Replication/frmReplicate/cmdExit_Click diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/replication.vbp b/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/replication.vbp new file mode 100644 index 0000000..73d1140 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/replication.vbp @@ -0,0 +1,34 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\WINNT\System32\stdole2.tlb#OLE Automation +Reference=*\G{10010001-E260-11CF-AE68-00AA004A34D5}#8.0#0#..\..\..\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll#Microsoft SQLDMO Object Library +Form=frmReplicate.frm +Startup="frmReplicate" +HelpFile="" +Command32="" +Name="Replication" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionCompanyName="home" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/replication.vbw b/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/replication.vbw new file mode 100644 index 0000000..147d128 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/Replication/code/replication.vbw @@ -0,0 +1 @@ +frmReplicate = 11, 13, 1116, 699, , 0, 0, 0, 0, C diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Form1.frm b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Form1.frm new file mode 100644 index 0000000..6477ac9 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Form1.frm @@ -0,0 +1,452 @@ +VERSION 5.00 +Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX" +Begin VB.Form frmQA + Caption = "Query Analyser Lite" + ClientHeight = 9450 + ClientLeft = 1680 + ClientTop = 3210 + ClientWidth = 14115 + LinkTopic = "Form1" + ScaleHeight = 9450 + ScaleWidth = 14115 + Begin MSFlexGridLib.MSFlexGrid msf_grid + Height = 3795 + Left = 270 + TabIndex = 12 + Top = 5400 + Width = 13635 + _ExtentX = 24051 + _ExtentY = 6694 + _Version = 393216 + End + Begin VB.TextBox txtDelimiter + Height = 315 + Left = 6570 + TabIndex = 10 + Top = 1380 + Width = 315 + End + Begin VB.OptionButton optGrid + Caption = "In grid" + Height = 285 + Left = 4800 + TabIndex = 9 + Top = 1890 + Width = 1935 + End + Begin VB.OptionButton optText + Caption = "In Text" + Height = 285 + Left = 4800 + TabIndex = 8 + Top = 1380 + Width = 1485 + End + Begin VB.CommandButton cmdLogon + Caption = "Connect" + BeginProperty Font + Name = "MS Sans Serif" + Size = 24 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 1575 + Left = 270 + TabIndex = 7 + Top = 630 + Width = 3825 + End + Begin VB.CommandButton cmdRun + Height = 525 + Left = 9960 + Picture = "Form1.frx":0000 + Style = 1 'Graphical + TabIndex = 6 + Top = 870 + Width = 795 + End + Begin VB.ComboBox cboDatabases + Height = 315 + Left = 4800 + TabIndex = 4 + Top = 960 + Width = 4065 + End + Begin VB.TextBox txtResults + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H000000FF& + Height = 3705 + Left = 270 + MultiLine = -1 'True + ScrollBars = 3 'Both + TabIndex = 3 + Top = 5430 + Width = 13635 + End + Begin VB.CommandButton cmdParse + Height = 555 + Left = 9090 + Picture = "Form1.frx":0442 + Style = 1 'Graphical + TabIndex = 1 + Top = 870 + Width = 795 + End + Begin VB.TextBox txtQuery + BeginProperty Font + Name = "MS Sans Serif" + Size = 12 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + ForeColor = &H80000001& + Height = 2955 + Left = 270 + MultiLine = -1 'True + ScrollBars = 3 'Both + TabIndex = 0 + Top = 2340 + Width = 13605 + End + Begin VB.Label Label2 + Caption = "Delimiter" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 285 + Left = 6900 + TabIndex = 11 + Top = 1410 + Width = 1065 + End + Begin VB.Label Label3 + Caption = "Database" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 4830 + TabIndex = 5 + Top = 720 + Width = 2925 + End + Begin VB.Label Label1 + Alignment = 2 'Center + Caption = "Mini QA" + BeginProperty Font + Name = "MS Sans Serif" + Size = 24 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 555 + Left = 11130 + TabIndex = 2 + Top = 870 + Width = 2715 + End +End +Attribute VB_Name = "frmQA" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Const TWIPS_PER_CHAR = 110 + +Dim oDatabase As SQLDMO.Database + +Private Sub ExecuteQuery(DatabaseName As String, Query As String, EXECType As Integer, i_IsGridOrText As Integer, Optional str_delimiter As String) + + Debug.Print "Executing a new Query " & Now() & " " & Query + + If i_IsGridOrText = 1 Then + + Debug.Print "To Text Output" + + Else + + Debug.Print "To Grid Output" + + End If + + Dim str_OutputText As String + Dim oQryresults As SQLDMO.QueryResults + Dim i As Integer + Dim j As Integer + Dim txt_Results As String + + txt_Results = "" + txtResults.Text = "" + + If str_delimiter = "" Then + + str_delimiter = "," + + End If + + On Error GoTo err_handler + + Select Case EXECType + + 'Only parse + + Case 1 + + msf_grid.Visible = False + txtResults.Visible = True + + oServer.Databases(DatabaseName).ExecuteImmediate Query, SQLDMOExec_ParseOnly + txtResults.Text = "Parse of query Completed successfully" + + 'This will actually execute the code + 'We need to see if the user has selected to + 'have the output to text or grid + 'we make one or the other visible. + + Case 2 + + Set oQryresults = oServer.Databases(DatabaseName).ExecuteWithResultsAndMessages(Query, Len(Query), str_OutputText) + + 'Regardless of selection if the rows returned are 0 then we use the text box + + If oQryresults.Rows = 0 Then + + txtResults.Text = "No Row(s) affected" + + Else + + 'Here we go + + If i_IsGridOrText = 1 Then 'Text + + msf_grid.Visible = False + txtResults.Visible = True + + 'First run through we want the column names. + + For j = 1 To oQryresults.Columns + + txt_Results = txt_Results & oQryresults.ColumnName(j) & str_delimiter + + Next j + + txt_Results = Left(txt_Results, Len(txt_Results) - 1) & vbCrLf + + 'Now we want the data + + For i = 1 To oQryresults.Rows + + For j = 1 To oQryresults.Columns + + txt_Results = txt_Results & oQryresults.GetColumnString(i, j) & str_delimiter + + Next j + + txt_Results = Left(txt_Results, Len(txt_Results) - 1) & vbCrLf + + Next i + + txtResults.Text = txt_Results + + Else + + 'We now want to do the grid work + + txtResults.Visible = False + + msf_grid.Visible = True + + msf_grid.Rows = 0 + msf_grid.Cols = oQryresults.Columns + msf_grid.FixedCols = 0 + + 'First run through we want the column names. + + For j = 1 To oQryresults.Columns + + txt_Results = txt_Results & oQryresults.ColumnName(j) & vbTab + + 'check column widths and resize + + If msf_grid.ColWidth(j - 1) < (Len(oQryresults.ColumnName(j)) * TWIPS_PER_CHAR) Then + + msf_grid.ColWidth(j - 1) = Len(oQryresults.ColumnName(j)) * TWIPS_PER_CHAR + + End If + + Next j + + msf_grid.AddItem txt_Results + + txt_Results = "" + + 'Now we want the data + + For i = 1 To oQryresults.Rows + + For j = 1 To oQryresults.Columns + + txt_Results = txt_Results & oQryresults.GetColumnString(i, j) & vbTab + + 'check column widths and resize + + If msf_grid.ColWidth(j - 1) < (Len(oQryresults.GetColumnString(i, j)) * TWIPS_PER_CHAR) Then + + msf_grid.ColWidth(j - 1) = Len(oQryresults.GetColumnString(i, j)) * TWIPS_PER_CHAR + + End If + + Next j + + msf_grid.AddItem txt_Results + + txt_Results = "" + + Next i + + End If + + End If + + End Select + + If str_OutputText <> "" Then + + txtResults.Text = txtResults.Text & vbCrLf & str_OutputText + + End If + + Exit Sub + +err_handler: + txtResults.Text = Err.Source & vbCrLf & Err.Description + Exit Sub + +End Sub + +Private Sub cmdLogon_Click() + + frmLogin.Show 1, Me + + If b_IsConnected = True Then + + MsgBox "Connected to " & glb_Server + ShowDatabases + + End If + +End Sub + +Private Sub ShowDatabases() + + cboDatabases.Clear + + If glb_Server <> "" Then + + For Each oDatabase In oServer.Databases + + cboDatabases.AddItem oDatabase.Name + + Next oDatabase + + End If + +End Sub + +Private Sub cmdParse_Click() + + If txtQuery.Text = "" Then + + txtResults.Text = "Command Completed Successfully - No Query Offered" + + ElseIf txtQuery.SelLength > 0 Then + + ExecuteQuery cboDatabases.Text, txtQuery.SelText, 1, 1 + + Else + + ExecuteQuery cboDatabases.Text, txtQuery.Text, 1, 1 + + End If + +End Sub + +Private Sub cmdRun_Click() + + 'If the user does not enter a query return polite message + + If txtQuery.Text = "" Then + + txtResults.Visible = True + + txtResults.Text = "Command Completed Successfully - No Query Offered" + + 'If they have actively selected text and the output is text then + + ElseIf txtQuery.SelLength > 0 And optText.Value = True Then + + ExecuteQuery cboDatabases.Text, txtQuery.SelText, 2, 1, txtDelimiter.Text + + 'If they have actively selected text and the output is grid then + + ElseIf txtQuery.SelLength > 0 And optText.Value = False Then + + ExecuteQuery cboDatabases.Text, txtQuery.SelText, 2, 2, txtDelimiter.Text + + 'If they want to execute the window and the output is text then + + ElseIf optText.Value = True Then + + ExecuteQuery cboDatabases.Text, txtQuery.Text, 2, 1, txtDelimiter.Text + + 'If they want to execute the window and the output is grid then + + ElseIf optText.Value = False Then + + ExecuteQuery cboDatabases.Text, txtQuery.Text, 2, 2, txtDelimiter.Text + + End If + +End Sub + +Private Sub Form_Load() + + optText.Value = True + txtResults.Visible = True + msf_grid.Visible = False + +End Sub + + + diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Form1.frx b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Form1.frx new file mode 100644 index 0000000..9800567 Binary files /dev/null and b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Form1.frx differ diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/MSSCCPRJ.SCC b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/MSSCCPRJ.SCC new file mode 100644 index 0000000..1d6a7fa --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/MSSCCPRJ.SCC @@ -0,0 +1,5 @@ +[SCC] +SCC=This is a source code control file +[Project1.vbp] +SCC_Project_Name=this project is not under source code control +SCC_Aux_Path= diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Module1.bas b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Module1.bas new file mode 100644 index 0000000..9359034 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Module1.bas @@ -0,0 +1,14 @@ +Attribute VB_Name = "Module1" +Option Explicit + +Public oServer As SQLDMO.SQLServer +Public glb_Server As String +Public b_IsConnected As Boolean + + +Sub main() +App.EXEName = "Lite QA" +App.Title = "Lite QA" +App.ProductName = "Lite QA" +b_IsConnected = False +End Sub diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Project1.csi b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Project1.csi new file mode 100644 index 0000000..5b13925 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Project1.csi @@ -0,0 +1,14 @@ +[History] +B0=Lite_QA/frmQA +B1=Lite_QA/frmQA/ExecuteQuery +B2=Lite_QA/frmQA/cmdParse_Click +B3=Lite_QA/Module1 +B4=Lite_QA/frmQA/cmdRun_Click +B5=Lite_QA/frmQA/cmdLogon_Click +B6=Lite_QA/frmLogin +B7=Lite_QA/frmQA/Form_Load +B8=Lite_QA/frmQA/ShowDatabases +B9=Lite_QA/frmLogin/cmdCancel_Click +B10=Lite_QA/frmLogin/Logon +B11=Lite_QA/frmLogin/cmdOK_Click +B12=Lite_QA/Module1/main diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Project1.vbp b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Project1.vbp new file mode 100644 index 0000000..ee7d445 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Project1.vbp @@ -0,0 +1,40 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\stdole2.tlb#OLE Automation +Reference=*\G{10010001-E260-11CF-AE68-00AA004A34D5}#7.0#0#C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll#Microsoft SQLDMO Object Library +Form=Form1.frm +Form=frmLogin.frm +Module=Module1; Module1.bas +Object={5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0; Msflxgrd.ocx +IconForm="frmQA" +Startup="frmQA" +HelpFile="" +Title="LiteQA" +Command32="" +Name="Lite_QA" +HelpContextID="0" +CompatibleMode="0" +MajorVer=1 +MinorVer=0 +RevisionVer=0 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionCompanyName="CMPI" +VersionProductName="Lite QA" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Project1.vbw b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Project1.vbw new file mode 100644 index 0000000..79e5637 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/Project1.vbw @@ -0,0 +1,3 @@ +frmQA = 18, 137, 1215, 1062, , 0, 0, 0, 0, C +frmLogin = 127, 14, 1224, 915, C, 0, 0, 0, 0, C +Module1 = 464, 51, 911, 601, C diff --git a/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/frmLogin.frm b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/frmLogin.frm new file mode 100644 index 0000000..0ce18b7 --- /dev/null +++ b/AM5DEV/TheFDrive/TheBook/Chapters/miniQA/QA/frmLogin.frm @@ -0,0 +1,199 @@ +VERSION 5.00 +Begin VB.Form frmLogin + BorderStyle = 3 'Fixed Dialog + Caption = "Login" + ClientHeight = 2835 + ClientLeft = 7050 + ClientTop = 6435 + ClientWidth = 4515 + LinkTopic = "Form1" + MaxButton = 0 'False + MinButton = 0 'False + ScaleHeight = 1675.012 + ScaleMode = 0 'User + ScaleWidth = 4239.34 + ShowInTaskbar = 0 'False + Begin VB.CheckBox chktrusted + Caption = "Use trusted Connection." + Height = 255 + Left = 120 + TabIndex = 8 + Top = 840 + Width = 3855 + End + Begin VB.ComboBox cboServer + Height = 315 + Left = 1290 + TabIndex = 7 + Top = 270 + Width = 2985 + End + Begin VB.TextBox txtUserName + Height = 345 + Left = 1290 + TabIndex = 1 + Top = 1245 + Width = 2955 + End + Begin VB.CommandButton cmdOK + Caption = "OK" + Default = -1 'True + Height = 390 + Left = 810 + TabIndex = 4 + Top = 2190 + Width = 1140 + End + Begin VB.CommandButton cmdCancel + Cancel = -1 'True + Caption = "Cancel" + Height = 390 + Left = 2415 + TabIndex = 5 + Top = 2190 + Width = 1140 + End + Begin VB.TextBox txtPassword + Height = 345 + IMEMode = 3 'DISABLE + Left = 1290 + PasswordChar = "*" + TabIndex = 3 + Top = 1635 + Width = 2955 + End + Begin VB.Label Label1 + Caption = "Server" + Height = 285 + Left = 120 + TabIndex = 6 + Top = 300 + Width = 1065 + End + Begin VB.Label lblLabels + Caption = "&User Name:" + Height = 270 + Index = 0 + Left = 105 + TabIndex = 0 + Top = 1260 + Width = 1080 + End + Begin VB.Label lblLabels + Caption = "&Password:" + Height = 270 + Index = 1 + Left = 105 + TabIndex = 2 + Top = 1650 + Width = 1080 + End +End +Attribute VB_Name = "frmLogin" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False + +Dim oRserver As SQLDMO.RegisteredServer +Dim oApp As SQLDMO.Application +Dim oGroup As SQLDMO.ServerGroup + +Private Sub ShowServers() + + Set oApp = New SQLDMO.Application + Set oGroup = New SQLDMO.ServerGroup + + For Each oGroup In oApp.ServerGroups + + For Each oRserver In oGroup.RegisteredServers + + cboServer.AddItem oRserver.Name + + Next oRserver + + Next oGroup + +End Sub + +Private Sub chktrusted_Click() + + If chktrusted.Value = vbChecked Then + + txtPassword.Locked = True + txtUserName.Locked = True + txtPassword.Enabled = False + txtUserName.Enabled = False + + Else + + txtPassword.Locked = False + txtUserName.Locked = False + txtPassword.Enabled = True + txtUserName.Enabled = True + + End If + +End Sub + +Private Sub cmdCancel_Click() + + Unload Me + +End Sub + +Private Sub cmdOK_Click() + + If cboServer.Text <> "" Then + + If chktrusted.Value = vbChecked Then + + Logon cboServer.Text, 1 + + Else + + Logon cboServer.Text, 0 + + End If + + End If + +End Sub + +Private Sub Form_Load() + + ShowServers + +End Sub + +Private Sub Logon(servername, Integrated As Integer) + + On Error GoTo err_handler + + Set oServer = New SQLDMO.SQLServer + + 'check whether we require trusted connection or not + + If Integrated = 1 Then + + oServer.LoginSecure = True + oServer.Connect servername + + Else + + oServer.Connect servername, txtUserName.Text, txtPassword.Text + + End If + + b_IsConnected = True + glb_Server = oServer.Name + Me.Visible = False + + Exit Sub + +err_handler: + MsgBox Err.Description, vbCritical, "Incorrect Login" + Exit Sub + +End Sub + diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..42e412a --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,27 @@ +Freeware License, some rights reserved + +Copyright (c) 2003 Allan Mitchell and Mark Allison + +Permission is hereby granted, free of charge, to anyone obtaining a copy +of this software and associated documentation files (the "Software"), +to work with the Software within the limits of freeware distribution and fair use. +This includes the rights to use, copy, and modify the Software for personal use. +Users are also allowed and encouraged to submit corrections and modifications +to the Software for the benefit of other users. + +It is not allowed to reuse, modify, or redistribute the Software for +commercial use in any way, or for a user’s educational materials such as books +or blog articles without prior permission from the copyright holder. + +The above copyright notice and this permission notice need to be included +in all copies or substantial portions of the software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a5c6974 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +#Apress Source Code + +This repository accompanies [*Real-World SQL-DMO for SQL Server*](http://www.apress.com/9781590590409) by Allan Mitchell and Mark Allison (Apress, 2003). + +![Cover image](9781590590409.jpg) + +Download the files as a zip using the green button, or clone the repository to your machine using Git. + +##Releases + +Release v1.0 corresponds to the code in the published book, without corrections or updates. + +##Contributions + +See the file Contributing.md for more information on how you can contribute to this repository. diff --git a/ServerInfoSource.zip b/ServerInfoSource.zip new file mode 100644 index 0000000..1358466 Binary files /dev/null and b/ServerInfoSource.zip differ diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..f6005ad --- /dev/null +++ b/contributing.md @@ -0,0 +1,14 @@ +# Contributing to Apress Source Code + +Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. + +## How to Contribute + +1. Make sure you have a GitHub account. +2. Fork the repository for the relevant book. +3. Create a new branch on which to make your change, e.g. +`git checkout -b my_code_contribution` +4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. +5. Submit a pull request. + +Thank you for your contribution! \ No newline at end of file diff --git a/scripter_v4.zip b/scripter_v4.zip new file mode 100644 index 0000000..c90b02b Binary files /dev/null and b/scripter_v4.zip differ