Aracılığıyla paylaş


clr tümleştirme Özel öznitelikler genel bakış

Ortak dil çalışma zamanı (clr), .NET Frameworkaçıklayıcı anahtar kelimeler, öznitelikler denen kullanılmasına. Bu öznitelikler, yöntemleri ve sınıfları gibi birçok unsurlar için ek bilgi sağlar. Öznitelikleri derleme nesne meta verileri ile kaydedilir ve diğer geliştirme araçları kodunuzu açıklamak için veya içindeki çalışma davranışını etkiler için kullanılabilir SQL Server.

Ne zaman sen sicil ile bir clr yordam SQL Server, SQL ServerÖzellikler hakkında rutin türetir. Bu rutin özellikleri rutin dizine dahil rutin, yeteneklerini belirler. Örneğin, ayarlama DataAccessözelliği DataAccessKind.Readveri erişim sağlar SQL Serverkullanıcı tablo içinde bir clr ilevi. Aşağıdaki örnekte basit bir durumda hangi gösterir DataAccessözelliği, bir kullanıcı tabloyu veri erişimi kolaylaştırmak için ayarlanmış table1.

using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Data.SqlClient;

public partial class UserDefinedFunctions
{
    [SqlFunction(DataAccess = DataAccessKind.Read)]
    public static string func1()
    {
        // Open a connection and create a command
        SqlConnection conn = new SqlConnection("context connection = true");
        conn.Open();
        SqlCommand cmd = conn.CreateCommand();
        cmd.CommandText = "SELECT str_val FROM table1 WHERE int_val = 10";
        // where table1 is a user table
        // Execute this command 
        SqlDataReader rd = cmd.ExecuteReader();
        // Set string ret_val to str_val returned from the query
        string ret_val = rd.GetValue(0).ToString();
        rd.Close();
        return ret_val;
    }
}
using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Data.SqlClient;

public partial class UserDefinedFunctions
{
    [SqlFunction(DataAccess = DataAccessKind.Read)]
    public static string func1()
    {
        // Open a connection and create a command
        SqlConnection conn = new SqlConnection("context connection = true");
        conn.Open();
        SqlCommand cmd = conn.CreateCommand();
        cmd.CommandText = "SELECT str_val FROM table1 WHERE int_val = 10";
        // where table1 is a user table
        // Execute this command 
        SqlDataReader rd = cmd.ExecuteReader();
        // Set string ret_val to str_val returned from the query
        string ret_val = rd.GetValue(0).ToString();
        rd.Close();
        return ret_val;
    }
}
Imports System
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Imports System.Data.SqlClient
 
Public partial Class UserDefinedFunctions
    <SqlFunction(DataAccess = DataAccessKind.Read)> _ 
    Public Shared Function func1() As String
        ' Open a connection and create a command
        Dim conn As SqlConnection = New SqlConnection("context connection = true") 
        conn.Open()
        Dim cmd As SqlCommand =  conn.CreateCommand() 
        cmd.CommandText = "SELECT str_val FROM table1 WHERE int_val = 10"
        ' where table1 is a user table
        ' Execute this command 
        Dim rd As SqlDataReader =  cmd.ExecuteReader() 
        ' Set string ret_val to str_val returned from the query
        Dim ret_val As String =  rd.GetValue(0).ToString() 
        rd.Close()
        Return ret_val
    End Function
End Class
Imports System
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Imports System.Data.SqlClient
 
Public partial Class UserDefinedFunctions
    <SqlFunction(DataAccess = DataAccessKind.Read)> _ 
    Public Shared Function func1() As String
        ' Open a connection and create a command
        Dim conn As SqlConnection = New SqlConnection("context connection = true") 
        conn.Open()
        Dim cmd As SqlCommand =  conn.CreateCommand() 
        cmd.CommandText = "SELECT str_val FROM table1 WHERE int_val = 10"
        ' where table1 is a user table
        ' Execute this command 
        Dim rd As SqlDataReader =  cmd.ExecuteReader() 
        ' Set string ret_val to str_val returned from the query
        Dim ret_val As String =  rd.GetValue(0).ToString() 
        rd.Close()
        Return ret_val
    End Function
End Class

İçin Transact-SQLrutinleri SQL Serverrutin özellikleri doğrudan rutin tanımından türetir. clr yordamları için sunucu bu özelliklerini türetmek için rutin vücut analiz değil. Bunun yerine, sınıfları için özel öznitelikleri kullanabilirsiniz ve sınıf üyeleri uygulanan bir .NET Frameworkdil.

clr yordamları, kullanıcı tanımlı türler ve toplamları için gerekli özel öznitelikleri tanımlanır Microsoft.SqlServer.Servernamespace.

Ayrıca bkz.

Kavramlar

clr yordamları için özel öznitelikleri