Aracılığıyla paylaş


smo özel durumları

De yönetilen kod, özel durum oluşturuldu bir hata oluştuğunda.smo yöntemlerini ve özelliklerini başarı veya başarısızlık değerde bildirmez.Bunun yerine, özel durum yakalandı ve olması bir özel durum işleyici tarafından işlenen.

smo farklı özel sınıflar mevcut.Özel durum hakkında bilgi ayıklanır özel durumu özellikleri gibi Message özellik sağlayan bir metin iletisi hakkında özel durum.

Özel durum işleme ifadeleri programlama diline özgüdür.Örneğin, Microsoft olduğu Visual Basic Catch deyim.

İç özel durumlar

Özel durumlar, genel veya özel olabilir.Ürün genelinde özel durumlar içeren bir küme , özel durum.Birkaç Catch ifadeleri kullanılabilir beklenen hataları işlemek ve izin kalan aracılığıyla hataları Sonbahar için genel özel durum işleme kodu.Özel durumlar genellikle basamaklı bir sırada ortaya çıkar.Sık sık, smo özel durum sql istisna olmuş olabilir.Bu algılamaya yol InnerException özellik son, üst düzey bir özel duruma neden durumun sırayla belirlemek için.

Not

The SQLException exception is declared in the System.Data.SqlClient namespace.

Özel durum düzeylerini gösteren diyagram

Diyagram uygulama katmanları üzerinden özel durumlara akışını göstermektedir.

Örnek

Sunulan kod örneklerinden herhangi birini kullanmak için, programlama ortamını, programlama şablonunu ve uygulamanızı oluşturacağınız programlama dilini seçmeniz gerekecektir.Daha fazla bilgi için bkz: [Howto:CreateaVisualBasicSMOProjectinVisualStudio.NET]Nasıl yapılır: Visual Studio'da Visual Basic smo proje oluşturun.NET veya [Howto:CreateaVisualC#SMOProjectinVisualStudio.NET]Nasıl yapılır: Bir Visual C# smo Project Visual Studio'da oluşturun.NET.

Visual Basic'te özel durum yakalama

Bu kod örneği nasıl kullanılacağını gösterir Try…Catch…Finally Visual Basic deyim smo özel durumu yakalamaktır.Tüm smo özel durumlar SmoException türüne sahip ve smo Başvurusu'nda listelenir.Sıra iç özel durum hata kökünü göstermek için görüntülenir.Daha fazla bilgi için bkz: Visual Basic .net belgeleri.

'This sample requires the Microsoft.SqlServer.Management.Smo.Agent namespace is included.
'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Define an Operator object variable by supplying the parent SQL Agent and the name arguments in the constructor.
'Note that the Operator type requires [] parenthesis to differentiate it from a Visual Basic key word.
Dim op As [Operator]
op = New [Operator](srv.JobServer, "Test_Operator")
op.Create()
'Start exception handling.
Try
    'Create the operator again to cause an SMO exception.
    Dim opx As OperatorCategory
    opx = New OperatorCategory(srv.JobServer, "Test_Operator")
    opx.Create()
    'Catch the SMO exception
Catch smoex As SmoException
    Console.WriteLine("This is an SMO Exception")
    'Display the SMO exception message.
    Console.WriteLine(smoex.Message)
    'Display the sequence of non-SMO exceptions that caused the SMO exception.
    Dim ex As Exception
    ex = smoex.InnerException
    Do While ex.InnerException IsNot (Nothing)
        Console.WriteLine(ex.InnerException.Message)
        ex = ex.InnerException
    Loop
    'Catch other non-SMO exceptions.
Catch ex As Exception
    Console.WriteLine("This is not an SMO exception.")
End Try

Bir Visual C# [NULL]'ta istisnalarını

Bu kod örneği nasıl kullanılacağını gösterir Try…Catch…Finally Visual C# deyim bir smo özel. yakalamak içinTüm smo özel durumlar SmoException türüne sahip ve smo Başvurusu'nda listelenir.Sıra iç özel durum hata kökünü göstermek için görüntülenir.Daha fazla bilgi için Visual C# belgelerine bakın.

{ 
//This sample requires the Microsoft.SqlServer.Management.Smo.Agent namespace to be included. 
//Connect to the local, default instance of SQL Server. 
Server srv; 
srv = new Server(); 
//Define an Operator object variable by supplying the parent SQL Agent and the name arguments in the constructor. 
//Note that the Operator type requires [] parenthesis to differentiate it from a Visual Basic key word. 
op = new Operator(srv.JobServer, "Test_Operator"); 
op.Create(); 
//Start exception handling. 
try { 
    //Create the operator again to cause an SMO exception. 
    OperatorCategory opx; 
    opx = new OperatorCategory(srv.JobServer, "Test_Operator"); 
    opx.Create(); 
} 
//Catch the SMO exception 
catch (SmoException smoex) { 
    Console.WriteLine("This is an SMO Exception"); 
   //Display the SMO exception message. 
   Console.WriteLine(smoex.Message); 
   //Display the sequence of non-SMO exceptions that caused the SMO exception. 
   Exception ex; 
   ex = smoex.InnerException; 
   while (!object.ReferenceEquals(ex.InnerException, (null))) { 
      Console.WriteLine(ex.InnerException.Message); 
      ex = ex.InnerException; 
    } 
    } 
   //Catch other non-SMO exceptions. 
   catch (Exception ex) { 
      Console.WriteLine("This is not an SMO exception."); 
} 
}