Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
Van toepassing op:SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
SQL-database in Microsoft Fabric Preview
In SMO bevatten het Information object, het Settings object, het UserOptions object en het Configuration object instellingen en informatie voor het exemplaar van Microsoft SQL Server.
SQL Server heeft talloze eigenschappen die het gedrag van het geïnstalleerde exemplaar beschrijven. De eigenschappen beschrijven de opstartopties, de standaardinstellingen van de server, bestanden en mappen, systeem- en processorgegevens, product- en versies, verbindingsgegevens, geheugenopties, taal- en sorteringsselecties en de verificatiemodus.
SQL Server-configuratie
De Information objecteigenschappen bevatten informatie over het exemplaar van SQL Server, zoals processor en platform.
De Settings objecteigenschappen bevatten informatie over het exemplaar van SQL Server. Het standaarddatabasebestand en de standaardmap kunnen worden gewijzigd naast het e-mailprofiel en het serveraccount. Deze eigenschappen blijven behouden voor de duur van de verbinding.
De UserOptions objecteigenschappen bevatten informatie over het huidige gedrag van verbindingen met betrekking tot rekenkundige, ANSI-standaarden en transacties.
Er is ook een set configuratieopties die wordt vertegenwoordigd door het Configuration object. Het bevat een set eigenschappen die de opties vertegenwoordigen die kunnen worden gewijzigd door de sp_configure opgeslagen procedure. Opties zoals Priority Boost, Herstelinterval en Netwerkpakketgrootte bepalen de prestaties van het exemplaar van SQL Server. Veel van deze opties kunnen dynamisch worden gewijzigd, maar in sommige gevallen wordt de waarde eerst geconfigureerd en vervolgens gewijzigd wanneer het exemplaar van SQL Server opnieuw wordt opgestart.
Er is een Configuration objecteigenschap voor elke configuratieoptie. Met behulp van het ConfigProperty object kunt u de globale configuratie-instelling wijzigen. Veel eigenschappen hebben maximum- en minimumwaarden die ook als eigenschappen worden opgeslagen ConfigProperty . Voor deze eigenschappen is de Alter methode vereist om de wijziging door te voeren in het exemplaar van SQL Server.
Alle configuratieopties in het Configuration object moeten worden gewijzigd door de systeembeheerder.
Examples
Voor de volgende codevoorbeelden moet u de programmeeromgeving, de programmeersjabloon en de programmeertaal selecteren om uw toepassing te maken. Zie Een Visual C# SMO-project maken in Visual Studio .NETvoor meer informatie.
Sql Server-configuratieopties wijzigen in Visual Basic
In het codevoorbeeld ziet u hoe u een configuratieoptie bijwerkt in Visual Basic .NET. Ook wordt informatie opgehaald en weergegeven over maximum- en minimumwaarden voor de opgegeven configuratieoptie. Ten slotte informeert het programma de gebruiker of de wijziging dynamisch is aangebracht of als deze is opgeslagen totdat het exemplaar van SQL Server opnieuw wordt opgestart.
'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Display all the configuration options.
Dim p As ConfigProperty
For Each p In srv.Configuration.Properties
Console.WriteLine(p.DisplayName)
Next
Console.WriteLine("There are " & srv.Configuration.Properties.Count.ToString & " configuration options.")
'Display the maximum and minimum values for ShowAdvancedOptions.
Dim min As Integer
Dim max As Integer
min = srv.Configuration.ShowAdvancedOptions.Minimum
max = srv.Configuration.ShowAdvancedOptions.Maximum
Console.WriteLine("Minimum and Maximum values are " & min & " and " & max & ".")
'Modify the value of ShowAdvancedOptions and run the Alter method.
srv.Configuration.ShowAdvancedOptions.ConfigValue = 0
srv.Configuration.Alter()
'Display when the change takes place according to the IsDynamic property.
If srv.Configuration.ShowAdvancedOptions.IsDynamic = True Then
Console.WriteLine("Configuration option has been updated.")
Else
Console.WriteLine("Configuration option will be updated when SQL Server is restarted.")
End If
SQL Server-instellingen wijzigen in Visual Basic
In het codevoorbeeld wordt informatie weergegeven over het exemplaar van SQL Server in Information en Settings, en worden instellingen gewijzigd in Settings en UserOptionsobjecteigenschappen.
In het voorbeeld hebben het UserOptions object en het Settings object beide een Alter methode. U kunt de Alter methoden voor deze afzonderlijk uitvoeren.
'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Display information about the instance of SQL Server in Information and Settings.
Console.WriteLine("OS Version = " & srv.Information.OSVersion)
Console.WriteLine("State = " & srv.Settings.State.ToString)
'Display information specific to the current user in UserOptions.
Console.WriteLine("Quoted Identifier support = " & srv.UserOptions.QuotedIdentifier)
'Modify server settings in Settings.
srv.Settings.LoginMode = ServerLoginMode.Integrated
'Modify settings specific to the current connection in UserOptions.
srv.UserOptions.AbortOnArithmeticErrors = True
'Run the Alter method to make the changes on the instance of SQL Server.
srv.Alter()
SQL Server-instellingen wijzigen in Visual C#
In het codevoorbeeld wordt informatie weergegeven over het exemplaar van SQL Server in Information en Settings, en worden instellingen gewijzigd in Settings en UserOptionsobjecteigenschappen.
In het voorbeeld hebben het UserOptions object en het Settings object beide een Alter methode. U kunt de Alter methoden voor deze afzonderlijk uitvoeren.
//Connect to the local, default instance of SQL Server.
{
Server srv = new Server();
//Display all the configuration options.
foreach (ConfigProperty p in srv.Configuration.Properties)
{
Console.WriteLine(p.DisplayName);
}
Console.WriteLine("There are " + srv.Configuration.Properties.Count.ToString() + " configuration options.");
//Display the maximum and minimum values for ShowAdvancedOptions.
int min = 0;
int max = 0;
min = srv.Configuration.ShowAdvancedOptions.Minimum;
max = srv.Configuration.ShowAdvancedOptions.Maximum;
Console.WriteLine("Minimum and Maximum values are " + min + " and " + max + ".");
//Modify the value of ShowAdvancedOptions and run the Alter method.
srv.Configuration.ShowAdvancedOptions.ConfigValue = 0;
srv.Configuration.Alter();
//Display when the change takes place according to the IsDynamic property.
if (srv.Configuration.ShowAdvancedOptions.IsDynamic == true)
{
Console.WriteLine("Configuration option has been updated.");
}
else
{
Console.WriteLine("Configuration option will be updated when SQL Server is restarted.");
}
}
SQL Server-instellingen wijzigen in PowerShell
In het codevoorbeeld wordt informatie weergegeven over het exemplaar van SQL Server in Information en Settings, en worden instellingen gewijzigd in Settings en UserOptionsobjecteigenschappen.
In het voorbeeld hebben het UserOptions object en het Settings object beide een Alter methode. U kunt de Alter methoden voor deze afzonderlijk uitvoeren.
# Set the path context to the local, default instance of SQL Server.
CD \sql\localhost\
$srv = get-item default
#Display information about the instance of SQL Server in Information and Settings.
"OS Version = " + $srv.Information.OSVersion
"State = "+ $srv.Settings.State.ToString()
#Display information specific to the current user in UserOptions.
"Quoted Identifier support = " + $srv.UserOptions.QuotedIdentifier
#Modify server settings in Settings.
$srv.Settings.LoginMode = [Microsoft.SqlServer.Management.SMO.ServerLoginMode]::Integrated
#Modify settings specific to the current connection in UserOptions.
$srv.UserOptions.AbortOnArithmeticErrors = $true
#Run the Alter method to make the changes on the instance of SQL Server.
$srv.Alter()
Sql Server-configuratieopties wijzigen in PowerShell
In het codevoorbeeld ziet u hoe u een configuratieoptie bijwerkt in Visual Basic .NET. Ook wordt informatie opgehaald en weergegeven over maximum- en minimumwaarden voor de opgegeven configuratieoptie. Ten slotte informeert het programma de gebruiker of de wijziging dynamisch is aangebracht of als deze is opgeslagen totdat het exemplaar van SQL Server opnieuw wordt opgestart.
#Get a server object which corresponds to the default instance replace LocalMachine with the physical server
cd \sql\LocalMachine
$svr = get-item default
#enumerate its properties
foreach ($Item in $Svr.Configuration.Properties)
{
$Item.DisplayName
}
"There are " + $svr.Configuration.Properties.Count.ToString() + " configuration options."
#Display the maximum and minimum values for ShowAdvancedOptions.
$min = $svr.Configuration.ShowAdvancedOptions.Minimum
$max = $svr.Configuration.ShowAdvancedOptions.Maximum
"Minimum and Maximum values are " + $min.ToString() + " and " + $max.ToString() + "."
#Modify the value of ShowAdvancedOptions and run the Alter method.
$svr.Configuration.ShowAdvancedOptions.ConfigValue = 0
$svr.Configuration.Alter()
#Display when the change takes place according to the IsDynamic property.
If ($svr.Configuration.ShowAdvancedOptions.IsDynamic -eq $true)
{
"Configuration option has been updated."
}
Else
{
"Configuration option will be updated when SQL Server is restarted."
}