This commit is contained in:
2026-06-29 07:28:49 -04:00
parent 08240122f9
commit 8261e25cfa
35 changed files with 178 additions and 958 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,14 +2,14 @@
"Version": 1,
"WorkspaceRootPath": "C:\\Repos\\kmSqlReplicate\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{364F9228-3601-4813-9E87-F042D9357580}|kmSqlReplicate.csproj|c:\\repos\\kmsqlreplicate\\classobj\\clsreplicatebase.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{364F9228-3601-4813-9E87-F042D9357580}|kmSqlReplicate.csproj|solutionrelative:classobj\\clsreplicatebase.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{364F9228-3601-4813-9E87-F042D9357580}|kmSqlReplicate.csproj|c:\\repos\\kmsqlreplicate\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{364F9228-3601-4813-9E87-F042D9357580}|kmSqlReplicate.csproj|solutionrelative:program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{364F9228-3601-4813-9E87-F042D9357580}|kmSqlReplicate.csproj|c:\\repos\\kmsqlreplicate\\classobj\\clsreplicatebase.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{364F9228-3601-4813-9E87-F042D9357580}|kmSqlReplicate.csproj|solutionrelative:classobj\\clsreplicatebase.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{364F9228-3601-4813-9E87-F042D9357580}|kmSqlReplicate.csproj|c:\\repos\\kmsqlreplicate\\classobj\\servicemain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{364F9228-3601-4813-9E87-F042D9357580}|kmSqlReplicate.csproj|solutionrelative:classobj\\servicemain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
@@ -22,7 +22,7 @@
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 12,
"SelectedChildIndex": 14,
"Children": [
{
"$type": "Bookmark",
@@ -74,13 +74,13 @@
},
{
"$type": "Document",
"DocumentIndex": 0,
"DocumentIndex": 1,
"Title": "ClsReplicateBase.cs",
"DocumentMoniker": "C:\\Repos\\kmSqlReplicate\\ClassObj\\ClsReplicateBase.cs",
"RelativeDocumentMoniker": "ClassObj\\ClsReplicateBase.cs",
"ToolTip": "C:\\Repos\\kmSqlReplicate\\ClassObj\\ClsReplicateBase.cs",
"RelativeToolTip": "ClassObj\\ClsReplicateBase.cs",
"ViewState": "AgIAAEIAAAAAAAAAAAAAAGEAAAAwAAAAAAAAAA==",
"ViewState": "AgIAAFsAAAAAAAAAAAAAAGYAAAAmAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-08-29T11:21:32.713Z",
"EditorCaption": ""
@@ -95,18 +95,17 @@
"RelativeToolTip": "ClassObj\\ServiceMain.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAABIAAAADAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-08-29T11:19:38.123Z",
"EditorCaption": ""
"WhenOpened": "2025-08-29T11:19:38.123Z"
},
{
"$type": "Document",
"DocumentIndex": 1,
"DocumentIndex": 0,
"Title": "Program.cs",
"DocumentMoniker": "C:\\Repos\\kmSqlReplicate\\Program.cs",
"RelativeDocumentMoniker": "Program.cs",
"ToolTip": "C:\\Repos\\kmSqlReplicate\\Program.cs",
"RelativeToolTip": "Program.cs",
"ViewState": "AgIAABgAAAAAAAAAAAAAACEAAAALAAAAAAAAAA==",
"ToolTip": "C:\\Repos\\kmSqlReplicate\\Program.cs*",
"RelativeToolTip": "Program.cs*",
"ViewState": "AgIAAA4AAAAAAAAAAAAYwCAAAAAOAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-08-29T11:13:28.917Z",
"EditorCaption": ""
+3 -4
View File
@@ -80,7 +80,7 @@
"RelativeDocumentMoniker": "ClassObj\\ClsReplicateBase.cs",
"ToolTip": "C:\\Repos\\kmSqlReplicate\\ClassObj\\ClsReplicateBase.cs",
"RelativeToolTip": "ClassObj\\ClsReplicateBase.cs",
"ViewState": "AgIAAF0AAAAAAAAAAAAAAHkAAABiAAAAAAAAAA==",
"ViewState": "AgIAAPgAAAAAAAAAAAAYwAwBAAAiAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-08-29T11:21:32.713Z",
"EditorCaption": ""
@@ -95,8 +95,7 @@
"RelativeToolTip": "ClassObj\\ServiceMain.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAABIAAAADAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-08-29T11:19:38.123Z",
"EditorCaption": ""
"WhenOpened": "2025-08-29T11:19:38.123Z"
},
{
"$type": "Document",
@@ -106,7 +105,7 @@
"RelativeDocumentMoniker": "Program.cs",
"ToolTip": "C:\\Repos\\kmSqlReplicate\\Program.cs",
"RelativeToolTip": "Program.cs",
"ViewState": "AgIAABgAAAAAAAAAAAAAACEAAAALAAAAAAAAAA==",
"ViewState": "AgIAAA4AAAAAAAAAAAAYwCAAAAAOAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-08-29T11:13:28.917Z",
"EditorCaption": ""
+73 -20
View File
@@ -1,5 +1,6 @@
using Dapper;
using Microsoft.Data.SqlClient;
using Microsoft.SqlServer.Management.Sdk.Sfc;
using Microsoft.SqlServer.Management.Smo;
using System;
using System.Collections.Generic;
@@ -73,21 +74,39 @@ internal class ClsReplicateBase
try
{
ScriptingOptions scrOptions1, scrOptions2, scrOptions3;
var dctOptions = new SortedDictionary<byte, ScriptingOptions>();
scrOptions1 = new ScriptingOptions() // Drop and Create
// Drops first
dctOptions.Add(0, new ScriptingOptions()
{
Default = true,
NoIdentities = true,
DriAll = false,
ScriptDrops = true,
//ScriptForCreateDrop = true,
//DriAllConstraints = true,
//DriForeignKeys = true,
IncludeIfNotExists = true,
//DriAllKeys = true,
//DriChecks = true,
//DriAll = true,
});
// Then CREATE
dctOptions.Add(1, new ScriptingOptions()
{
Default = true,
NoIdentities = false,
ScriptDrops = false,
ScriptOwner = false,
NoFileGroup = false,
NoIndexPartitioningSchemes = true,
NoTablePartitioningSchemes = true,
ScriptForCreateDrop = true
};
scrOptions2 = new ScriptingOptions() // Get all keys and indexes
DriDefaults = true,
//DriForeignKeys = true,
//ScriptForCreateDrop = true,
//Statistics = true,
//Triggers = true,
});
// Get all keys and indexes
dctOptions.Add(2, new ScriptingOptions()
{
Default = false,
DriPrimaryKey = true,
@@ -97,12 +116,13 @@ internal class ClsReplicateBase
NoIndexPartitioningSchemes = true,
NoTablePartitioningSchemes = true,
ScriptForCreateDrop = true
};
scrOptions3 = new ScriptingOptions() // Get the permissions
});
// Get the permissions
dctOptions.Add(3, new ScriptingOptions()
{
Default = false,
Permissions = true
};
});
using (var cnSrc = new SqlConnection(string.Format("Server={0};Database={1};Integrated Security=SSPI;TrustServerCertificate=True;", itm1.FromServer.ToString(), itm1.FromDatabase.ToString())))
{
@@ -113,16 +133,49 @@ internal class ClsReplicateBase
foreach (DataRow dr in tbMain2.Rows)
{
Table T1;
var scrOutput = new StringCollection();
Table T1 = D1.Tables[dr["TableName"].ToString(), dr["SchemaName"].ToString()];
var txtSql = new StringBuilder();
T1 = D1.Tables[dr["TableName"].ToString(), dr["SchemaName"].ToString()];
txtSql.AppendFormat("DROP TABLE IF EXISTS [{0}].[{1}]\nGO\n\n", dr["SchemaName"].ToString(), dr["TableName"].ToString());
txtSql.Append(string.Join("\n", T1.Script(scrOptions1).Cast<string>().ToArray()));
txtSql.AppendLine("\nGO\n");
txtSql.Append(string.Join("\n", T1.Script(scrOptions2).Cast<string>().ToArray()));
txtSql.AppendLine("\nGO\n");
foreach (var kvp in dctOptions)
{
if (true)
{
txtSql.Append(string.Join("\n", T1.Script(kvp.Value).Cast<string>().ToArray()));
txtSql.AppendLine("\nGO\n");
}
else
{ // need to figure out how to handle foreign table relationships first
var scr = new Scripter(S1) { Options = kvp.Value };
var dw = new DependencyWalker(S1);
var dwTree = dw.DiscoverDependencies(new Urn[] { T1.Urn }, true);
var ddd = dw.WalkDependencies(dwTree);
foreach (var d in ddd)
{
bool needGo = false;
foreach (var s in scr.EnumScript(new[] { d.Urn }))
{
if (!string.IsNullOrWhiteSpace(s))
{
txtSql.AppendLine(s.ToString() + "\n");
needGo = true;
}
}
if (needGo)
txtSql.AppendLine("\nGO\n\n");
}
}
}
//T1 = D1.Tables[dr["TableName"].ToString(), dr["SchemaName"].ToString()];
//txtSql.AppendFormat("DROP TABLE IF EXISTS [{0}].[{1}]\nGO\n\n", dr["SchemaName"].ToString(), dr["TableName"].ToString());
//txtSql.Append(string.Join("\n", T1.Script(scrOptions1).Cast<string>().ToArray()));
//txtSql.AppendLine("\nGO\n");
//txtSql.Append(string.Join("\n", T1.Script(scrOptions2).Cast<string>().ToArray()));
//txtSql.AppendLine("\nGO\n");
//txtSql.Append(string.Join("\n", T1.Script(scrOptions3).Cast<string>().ToArray()));
//txtSql.AppendLine("\nGO\n");
dr["Sql"] = txtSql.ToString();
//
@@ -139,7 +192,7 @@ internal class ClsReplicateBase
if (D2.Tables.Contains(dr["TableName"].ToString(), dr["SchemaName"].ToString()))
{
Table T2 = D2.Tables[dr["TableName"].ToString(), dr["SchemaName"].ToString()];
sqlTablePermissions = string.Join("\n", T2.Script(scrOptions3).Cast<string>().ToArray());
sqlTablePermissions = string.Join("\n", T2.Script(dctOptions[3]).Cast<string>().ToArray());
}
S2.ConnectionContext.BatchSeparator = "GO";
@@ -254,7 +307,7 @@ internal class ClsReplicateBase
{
case "day":
case "days":
dtNextExecution=dtNextExecution.AddDays(IntervalNumber); break;
dtNextExecution = dtNextExecution.AddDays(IntervalNumber); break;
case "hour":
case "hours":
dtNextExecution = dtNextExecution.AddHours(IntervalNumber); break;
+62 -62
View File
@@ -30,9 +30,13 @@ internal class Program
SetProgramVersion();
if (Debugger.IsAttached)
{
var obj = new ClsReplicateBase();
obj.Go();
//Test1();
if (true)
{
var obj = new ClsReplicateBase();
obj.Go();
}
else
Test1();
}
else
{
@@ -75,34 +79,24 @@ internal class Program
internal static void Test1()
{
ScriptingOptions scrOptions1, scrOptions2, scrOptions3, scrOptions4;
var dctOptions = new SortedDictionary<byte, ScriptingOptions>();
scrOptions1 = new ScriptingOptions() // Drops first
// Drops first
dctOptions.Add(0, new ScriptingOptions()
{
Default = true,
//NoIdentities = true,
ScriptDrops = true,
//ScriptOwner = true,
//NoFileGroup = false,
//NoIndexPartitioningSchemes = true,
//NoTablePartitioningSchemes = true,
ScriptForCreateDrop = true,
DriAllConstraints = true,
//DriDefaults = true,
DriForeignKeys = true,
//ScriptForCreateDrop = true,
//DriAllConstraints = true,
//DriForeignKeys = true,
IncludeIfNotExists = true,
//EnforceScriptingOptions = true,
//AllowSystemObjects = false,
//Indexes = true,
DriAllKeys = true,
DriChecks = true,
//FullTextIndexes = true,
//Statistics = true,
//Triggers = true,
//WithDependencies = true,
DriAll = true,
};
scrOptions2 = new ScriptingOptions() // Then CREATE
//DriAllKeys = true,
//DriChecks = true,
//DriAll = true,
//WithDependencies = false,
});
// Then CREATE
dctOptions.Add(1, new ScriptingOptions()
{
Default = true,
NoIdentities = false,
@@ -111,11 +105,13 @@ internal class Program
NoFileGroup = false,
NoIndexPartitioningSchemes = true,
NoTablePartitioningSchemes = true,
DriDefaults = true,
//ScriptForCreateDrop = true,
//Statistics = true,
//Triggers = true,
};
scrOptions3 = new ScriptingOptions() // Get all keys and indexes
});
// Get all keys and indexes
dctOptions.Add(2, new ScriptingOptions()
{
Default = false,
DriPrimaryKey = true,
@@ -124,15 +120,14 @@ internal class Program
NoFileGroup = false,
NoIndexPartitioningSchemes = true,
NoTablePartitioningSchemes = true,
ScriptForCreateDrop = true,
FullTextIndexes = true,
DriAll = true
};
scrOptions4 = new ScriptingOptions() // Get the permissions
ScriptForCreateDrop = true
});
// Get the permissions
dctOptions.Add(3, new ScriptingOptions()
{
Default = false,
Permissions = true
};
});
using (var cnSrc = new SqlConnection(string.Format("Server={0};Database={1};Integrated Security=SSPI;TrustServerCertificate=True;", "BigMac", "MyCarHQ")))
{
@@ -143,47 +138,52 @@ internal class Program
Server S1 = new Server(new Microsoft.SqlServer.Management.Common.ServerConnection(cnSrc));
Database D1 = S1.Databases["MyCarHQ"];
Table T1 = D1.Tables["SourceFiles", "appt"];
//Table T1 = D1.Tables["SourceFiles", "appt"];
Table T1 = D1.Tables["ConversationMaster", "conv"];
//foreach (var fk in T1.ForeignKeys)
// Console.WriteLine("DROP " + fk.ToString());
var scr = new Scripter(S1) { Options = scrOptions1 };
//scr.Options.IncludeIfNotExists = true;
//scr.Options.ScriptSchema = true;
//scr.Options.ScriptDrops = true;
//Console.WriteLine (scr.EnumScript(new Urn[] { T1.Urn }).ToString());
var dw = new DependencyWalker(S1);
var dwTree = dw.DiscoverDependencies(new Urn[] { T1.Urn }, true);
var ddd = dw.WalkDependencies(dwTree);
foreach (var d in ddd)
foreach (var kvp in dctOptions)
{
foreach (var s in scr.EnumScript(new[] { d.Urn }))
if (true)
{
Console.WriteLine(s);
txtSql.Append(string.Join("\n", T1.Script(kvp.Value).Cast<string>().ToArray()));
txtSql.AppendLine("\nGO\n");
}
else
{
var scr = new Scripter(S1) { Options = kvp.Value };
var dw = new DependencyWalker(S1);
var dwTree = dw.DiscoverDependencies(new Urn[] { T1.Urn }, true);
var ddd = dw.WalkDependencies(dwTree);
foreach (var d in ddd)
{
bool needGo = false;
foreach (var s in scr.EnumScript(new[] { d.Urn }))
{
if (!string.IsNullOrWhiteSpace(s))
{
txtSql.AppendLine(s.ToString() + "\n");
needGo = true;
}
}
if (needGo)
txtSql.AppendLine("\nGO\n\n");
}
}
}
//foreach (string s in scr.EnumScript(new Urn[] { T1.Urn }))
// Console.WriteLine(s + "\n\n");
//Console.ReadLine();
Console.WriteLine(txtSql.ToString());
Console.ReadLine();
if (false)
{
txtSql.Append(string.Join("\n", T1.Script(scrOptions1).Cast<string>().ToArray()));
txtSql.AppendLine("\nGO\n\n\n\n");
txtSql.Append(string.Join("\n", T1.Script(scrOptions2).Cast<string>().ToArray()));
txtSql.AppendLine("\nGO\n\n\n\n");
txtSql.Append(string.Join("\n", T1.Script(scrOptions3).Cast<string>().ToArray()));
txtSql.AppendLine("\nGO\n");
Console.WriteLine(txtSql.ToString());
Console.ReadLine();
}
}
}
}
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("kmSqlReplicate")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+08240122f97b77a4990a95268adc05bfa2ed8798")]
[assembly: System.Reflection.AssemblyProductAttribute("kmSqlReplicate")]
[assembly: System.Reflection.AssemblyTitleAttribute("kmSqlReplicate")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
7f611e62edce65adfad9b656e8935ba93f5b2589e121239c7fed8a37da642195
e3ce1bfb1365c8eef05874f183def1ce44657db0129037c0b84bd90a1405674b
@@ -1,11 +1,14 @@
is_global = true
build_property.TargetFramework = net9.0
build_property.TargetFrameworkIdentifier = .NETCoreApp
build_property.TargetFrameworkVersion = v9.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property.EntryPointFilePath =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = kmSqlReplicate
build_property.ProjectDir = C:\Repos\kmSqlReplicate\
@@ -1,8 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using System;
global using System.Collections.Generic;
global using System.IO;
global using System.Linq;
global using System.Net.Http;
global using System.Threading;
global using System.Threading.Tasks;
Binary file not shown.
@@ -1 +1 @@
2e17a1fbbc3fc86c0f9909b5fc23c8e1ae68e238fc5f86efe9473f548bc7c139
e2a3d1591c3b8817afd51ed75cb690f55da77c90e13a5bcecbe6a216a417bcf5
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4 -2
View File
@@ -33,6 +33,7 @@
},
"frameworks": {
"net9.0": {
"framework": "net9.0",
"targetAlias": "net9.0",
"projectReferences": {}
}
@@ -47,10 +48,11 @@
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.300"
"SdkAnalysisLevel": "10.0.300"
},
"frameworks": {
"net9.0": {
"framework": "net9.0",
"targetAlias": "net9.0",
"dependencies": {
"Dapper": {
@@ -98,7 +100,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.304/PortableRuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\10.0.301/PortableRuntimeIdentifierGraph.json"
}
}
}
+1 -1
View File
@@ -7,7 +7,7 @@
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\RDeck.KEYMTV\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.14.1</NuGetToolVersion>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">7.0.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\RDeck.KEYMTV\.nuget\packages\" />
+5 -3
View File
@@ -1,5 +1,5 @@
{
"version": 3,
"version": 4,
"targets": {
"net9.0": {
"Azure.Core/1.47.1": {
@@ -6051,6 +6051,7 @@
},
"frameworks": {
"net9.0": {
"framework": "net9.0",
"targetAlias": "net9.0",
"projectReferences": {}
}
@@ -6065,10 +6066,11 @@
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.300"
"SdkAnalysisLevel": "10.0.300"
},
"frameworks": {
"net9.0": {
"framework": "net9.0",
"targetAlias": "net9.0",
"dependencies": {
"Dapper": {
@@ -6116,7 +6118,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.304/PortableRuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\10.0.301/PortableRuntimeIdentifierGraph.json"
}
}
},
+1 -1
View File
@@ -1,6 +1,6 @@
{
"version": 2,
"dgSpecHash": "/WmZSgAk970=",
"dgSpecHash": "LtJHdaAaCaw=",
"success": true,
"projectFilePath": "C:\\Repos\\kmSqlReplicate\\kmSqlReplicate.csproj",
"expectedPackageFiles": [