Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 73 additions & 5 deletions src/ScriptSqlConfig/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ 2. It will use trusted authentication unless both the /username
#if DEBUG
Console.WriteLine("");
Console.WriteLine("Press any key to continue....");
Console.ReadLine();
Console.ReadKey(false);
#endif


Expand Down Expand Up @@ -205,10 +205,10 @@ 2. It will use trusted authentication unless both the /username

#if DEBUG
Console.WriteLine("Press any key to continue....");
Console.ReadLine();
Console.ReadKey(false);
#endif
}

}

private static void SetVersions(string server)
{
Expand Down Expand Up @@ -276,6 +276,7 @@ private static void ScriptInstance(string server, string directory)
ScriptEventNotifications(conn, instanceDirectory, so);
ScriptOtherObjects(srv, instanceDirectory, so);
ScriptDatabaseOptions(srv, instanceDirectory, so);
ScriptResourceGovernor(srv, instanceDirectory, so);

WriteMessage("Scripting User Objects and Security in System Databases...");
ScriptDatabase(srv.Name.ToString(), "master", Path.Combine(instanceDirectory, @"Databases\master"));
Expand Down Expand Up @@ -1434,7 +1435,74 @@ private static void ScriptDatabaseRoles(Database db, string directory, Scripting

}

private static void RemoveSqlFiles(string directory)

private static void ScriptResourceGovernor(Server smoServer, string directory, ScriptingOptions options)
{
if (VERBOSE)
WriteMessage("Resource Governor...");

StringCollection sc = new StringCollection();

if (smoServer.Edition.Contains("Enterprise") || smoServer.Edition.Contains("Developer"))
{
ResourceGovernor rg = smoServer.ResourceGovernor;
if (rg != null)
{
sc.Add("USE master;");
string classifierFunction = rg.ClassifierFunction;

if (!String.IsNullOrEmpty(classifierFunction))
{
int objId = -1;
using (SqlConnection conn = GetConnection(smoServer.Name, "master"))
{
string sql = "SELECT OBJECT_ID(@name)";
SqlCommand cmd = new SqlCommand(sql);
cmd.Connection = conn;
cmd.Connection.Open();
cmd.Parameters.Add(new SqlParameter("@name", System.Data.SqlDbType.NVarChar, 200));
cmd.Parameters[0].Value = classifierFunction;
objId = (int)(cmd.ExecuteScalar());
}



foreach (UserDefinedFunction udf in smoServer.Databases["master"].UserDefinedFunctions)
{
if (udf.ID == objId)
{
//if possible, script classifier function
sc.Add("ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = NULL);");
sc.Add("ALTER RESOURCE GOVERNOR DISABLE;");
sc.Append(udf.Script(options));
break;
}

}

// script Resource Governor configurations
sc.Append(rg.Script(options));

// script Resource Pools
foreach (ResourcePool pool in rg.ResourcePools)
{
sc.Append(pool.Script(options));

// script Workload Groups
foreach (WorkloadGroup wg in pool.WorkloadGroups)
{
sc.Append(wg.Script(options));
}
}

WriteFile(sc, Path.Combine(directory, "ResourceGovernor.sql"), true);
}
}
}
}


private static void RemoveSqlFiles(string directory)
{
throw new NotImplementedException("RemoveSqlFiles shouldn't be called.");
//DirectoryInfo dir = new DirectoryInfo(directory);
Expand Down
4 changes: 2 additions & 2 deletions src/ScriptSqlConfig/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2012.5")]
[assembly: AssemblyFileVersion("2012.5")]
[assembly: AssemblyVersion("2016.1")]
[assembly: AssemblyFileVersion("2016.1")]
25 changes: 17 additions & 8 deletions src/ScriptSqlConfig/ScriptSqlConfig.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,24 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.SqlServer.ConnectionInfo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL" />
<Reference Include="Microsoft.SqlServer.ConnectionInfo.11.0.0.0.Fakes">
<HintPath>FakesAssemblies\Microsoft.SqlServer.ConnectionInfo.11.0.0.0.Fakes.dll</HintPath>
<Reference Include="Microsoft.SqlServer.ConnectionInfo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Microsoft.SqlServer.ConnectionInfoExtended, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Microsoft.SqlServer.Management.Sdk.Sfc, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Microsoft.SqlServer.Smo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Microsoft.SqlServer.SmoExtended, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Microsoft.SqlServer.SqlEnum, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Microsoft.SqlServer.ConnectionInfoExtended, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL" />
<Reference Include="Microsoft.SqlServer.Management.Sdk.Sfc, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL" />
<Reference Include="Microsoft.SqlServer.Smo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL" />
<Reference Include="Microsoft.SqlServer.SmoExtended, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL" />
<Reference Include="Microsoft.SqlServer.SqlEnum, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand Down