다음을 통해 공유


SMO에서 SQL Server 구성

적용 대상: SQL ServerAzure SQL Database Azure SQL Managed Instance Azure Synapse Analytics

SMO에서 개체, Information Settings 개체, UserOptions 개체 및 Configuration 개체에는 Microsoft SQL Server 인스턴스에 대한 설정 및 정보가 포함됩니다.

SQL Server에는 설치된 인스턴스의 동작을 설명하는 다양한 속성이 있습니다. 속성은 시작 옵션, 서버 기본값, 파일 및 디렉터리, 시스템 및 프로세서 정보, 제품 및 버전, 연결 정보, 메모리 옵션, 언어 및 데이터 정렬 선택 및 인증 모드를 설명합니다.

SQL Server 구성

개체 속성에는 Information 프로세서 및 플랫폼과 같은 SQL Server 인스턴스에 대한 정보가 포함됩니다.

개체 속성에는 Settings SQL Server 인스턴스에 대한 정보가 포함됩니다. 메일 프로필 및 서버 계정 외에도 기본 데이터베이스 파일 및 디렉터리를 수정할 수 있습니다. 이러한 속성은 연결 기간 동안 유지됩니다.

개체 속성에는 UserOptions 산술, ANSI 표준 및 트랜잭션과 관련된 현재 연결 동작에 대한 정보가 포함됩니다.

개체가 나타내는 Configuration 구성 옵션 집합도 있습니다. 여기에는 sp_configure 저장 프로시저에서 수정할 수 있는 옵션을 나타내는 속성 집합이 포함되어 있습니다. 우선 순위 상승, 복구 간격네트워크 패킷 크기와같은 옵션은 SQL Server 인스턴스의 성능을 제어합니다. 이러한 옵션 중 대부분은 동적으로 변경할 수 있지만 경우에 따라 SQL Server 인스턴스가 다시 시작될 때 값이 먼저 구성되고 변경됩니다.

모든 구성 옵션에 Configuration 대한 개체 속성이 있습니다. 개체를 ConfigProperty 사용하여 전역 구성 설정을 수정할 수 있습니다. 많은 속성에는 속성으로 ConfigProperty 저장되는 최대값과 최소값이 있습니다. 이러한 속성을 사용하려면 Alter SQL Server 인스턴스에 변경 내용을 커밋해야 합니다.

Configuration 개체의 모든 구성 옵션은 시스템 관리자가 변경해야 합니다.

예제

다음 코드 예제를 사용하려면 애플리케이션을 만들 프로그래밍 환경, 프로그래밍 템플릿 및 프로그래밍 언어를 선택해야 합니다. 자세한 내용은 Visual Studio .NET에서 Visual C# SMO 프로젝트 만들기를 참조하세요.

Visual Basic에서 SQL Server 구성 옵션 수정

코드 예제는 Visual Basic .NET에서 구성 옵션을 업데이트하는 방법을 보여 줍니다. 또한 지정된 구성 옵션에 대한 최대값 및 최소값 정보를 검색하고 표시합니다. 마지막으로, 프로그램은 사용자에게 변경 내용이 동적으로 적용되었는지 또는 SQL Server 인스턴스가 다시 시작될 때까지 저장되었는지를 알려줍니다.

'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

Visual Basic에서 SQL Server 설정 수정

코드 예제에서는 SQL Server Information 의 인스턴스에 대한 정보를 표시하고 Settings, 설정 SettingsUserOptions개체 속성을 수정합니다.

예제 UserOptions 에서 개체와 Settings 개체에는 모두 메서드가 있습니다 Alter . 이러한 메서드를 Alter 개별적으로 실행할 수 있습니다.

'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()

Visual C에서 SQL Server 설정 수정#

코드 예제에서는 SQL Server Information 의 인스턴스에 대한 정보를 표시하고 Settings, 설정 SettingsUserOptions개체 속성을 수정합니다.

예제 UserOptions 에서 개체와 Settings 개체에는 모두 메서드가 있습니다 Alter . 이러한 메서드를 Alter 개별적으로 실행할 수 있습니다.

//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.");  
            }  
        }  

PowerShell에서 SQL Server 설정 수정

코드 예제에서는 SQL Server Information 의 인스턴스에 대한 정보를 표시하고 Settings, 설정 SettingsUserOptions개체 속성을 수정합니다.

예제 UserOptions 에서 개체와 Settings 개체에는 모두 메서드가 있습니다 Alter . 이러한 메서드를 Alter 개별적으로 실행할 수 있습니다.

# 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()  

PowerShell에서 SQL Server 구성 옵션 수정

코드 예제는 Visual Basic .NET에서 구성 옵션을 업데이트하는 방법을 보여 줍니다. 또한 지정된 구성 옵션에 대한 최대값 및 최소값 정보를 검색하고 표시합니다. 마지막으로, 프로그램은 사용자에게 변경 내용이 동적으로 적용되었는지 또는 SQL Server 인스턴스가 다시 시작될 때까지 저장되었는지를 알려줍니다.

#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."  
}