Kodlama ve kod görev hata ayıklama

Komut dosyası yapılandırdıktan sonra görev Komut dosyası görev Düzenleyicisi, komut dosyası görev geliştirme ortamında özel kodunuzu yazın.

Komut dosyası görev geliştirme ortamı

The Script task uses Microsoft Visual Studio Tools for Applications (VSTA) as the development environment for the script itself.

Script code is written in Microsoft Visual Basic 2008 or Microsoft Visual C# 2008.Ayarlayarak komut dosyası dilini belirtme ScriptLanguage özellik , Komut dosyası görev Düzenleyicisi.Başka bir programlama dili kullanmak isterseniz, özel bir derleme seçim dilinizi geliştirmek ve Script görev kodu kendi işlevleri çağırmanıza.

Komut dosyası görev oluşturma komut dosyası saklanır paket tanımı.Hiç ayrı komut dosyası vardır.Bu nedenle, paket dağıtım komut dosyası Görev Kullanımı etkilemez.

Not

Paket tasarlama ve komut dosyası hata ayıklama, komut dosyası kodu geçici olarak bir proje dosyasına yazılır.Önemli bilgileri bir dosyada saklamak olası bir güvenlik riski olduğundan, komut dosyası kodu içinde parolalar gibi önemli bilgiler eklemeyin öneririz.

Varsayılan olarak, Option Strict devre dışı IDE.

Komut dosyası görev proje yapısı

Oluşturmak veya bir komut dosyası görevi bulunan komut dosyasında değişiklik yapmak, vsta boş yeni bir proje açar veya varolan projeyi yeniden açar.Proje içinde paket dosyası olduğundan bu vsta proje oluşturma paketi dağıtımını etkilemez; komut dosyası görev ek dosyalar oluşturmaz.

Öğeleri ve sınıfları Script görev projedeki proje

vsta Project Explorer penceresinde görüntülenen komut dosyası görev project varsayılan olarak, tek bir öğe içeren ScriptMain.The ScriptMain item, in turn, contains a single class, also named ScriptMain.Sınıfındaki kod öğeler Script görev için seçtiğiniz programlama dili bağlı olarak değişiklik gösterebilir:

  • Ne zaman komut dosyası görev yapılandırılmış için Visual Basic 2008 programlama dili, ScriptMain sınıfı olan ortak bir alt yordam Main.The ScriptMain.Main subroutine is the method that the runtime calls when you run your Script task.

    Varsayılan olarak, yalnızca kod, Main Yeni bir komut dosyası alt satırı ise Dts.TaskResult = ScriptResults.Success.Bu satır, görevi kendi işleminde başarılı çalışma zamanı bildirir.The Dts.TaskResult property is discussed in Komut dosyası görev sonuçları döndürülüyor.

  • Ne zaman komut dosyası görev yapılandırılmış için Visual C# 2008 programlama dili, ScriptMain sınıfın genel bir yöntem var Main.Komut dosyası görev çalıştırıldığında yöntem çağrılır.

    Varsayılan olarak, Main yöntem içeren satırı Dts.TaskResult = (int)ScriptResults.Success.Bu satır, görevi kendi işleminde başarılı çalışma zamanı bildirir.

The ScriptMain item can contain classes other than the ScriptMain class.Sınıflar sadece içinde bulundukları Script görev için kullanılabilir.

Varsayılan olarak, ScriptMain Proje öğe aşağıdaki otomatik kod içerir:

' Microsoft SQL Server Integration Services Script Task
' Write scripts using Microsoft Visual Basic 2008.
' The ScriptMain is the entry point class of the script.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime.VSTAProxy

<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
Partial Class ScriptMain

Private Sub ScriptMain_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

End Sub

Private Sub ScriptMain_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
Try
' Unlock variables from the read-only and read-write variable collection properties
If (Dts.Variables.Count <> 0) Then
Dts.Variables.Unlock()
End If
Catch ex As Exception
        End Try
End Sub

Enum ScriptResults
Success = DTSExecResult.Success
Failure = DTSExecResult.Failure
End Enum


' The execution engine calls this method when the task executes.
' To access the object model, use the Dts property. Connections, variables, events,
' and logging features are available as members of the Dts property as shown in the following examples.
'
' To reference a variable, call Dts.Variables("MyCaseSensitiveVariableName").Value
' To post a log entry, call Dts.Log("This is my log text", 999, Nothing)
' To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, True)
'
' To use the connections collection use something like the following:
' ConnectionManager cm = Dts.Connections.Add("OLEDB")
' cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks2008R2;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;"
'
' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
' 
' To open Help, press F1.

Public Sub Main()
'
' Add your code here
'
Dts.TaskResult = ScriptResults.Success
End Sub

End Class
/*
   Microsoft SQL Server Integration Services Script Task
   Write scripts using Microsoft Visual C# 2008.
   The ScriptMain is the entry point class of the script.
*/

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime.VSTAProxy;
using System.Windows.Forms;

namespace ST_1bcfdbad36d94f8ba9f23a10375abe53.csproj
{
    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain
    {
        private void ScriptMain_Startup(object sender, EventArgs e)
        {

        }

        private void ScriptMain_Shutdown(object sender, EventArgs e)
        {
            try
            {
                // Unlock variables from the read-only and read-write variable collection properties
                if (Dts.Variables.Count != 0)
                {
                    Dts.Variables.Unlock();
                }
            }
            catch
            {
            }
        }

        #region VSTA generated code
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ScriptMain_Startup);
            this.Shutdown += new System.EventHandler(ScriptMain_Shutdown);
        }
        enum ScriptResults
        {
            Success = DTSExecResult.Success,
            Failure = DTSExecResult.Failure
        };

        #endregion

        /*
The execution engine calls this method when the task executes.
To access the object model, use the Dts property. Connections, variables, events,
and logging features are available as members of the Dts property as shown in the following examples.

To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
To post a log entry, call Dts.Log("This is my log text", 999, null);
To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);

To use the connections collection use something like the following:
ConnectionManager cm = Dts.Connections.Add("OLEDB");
cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks2008R2;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";

Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.

To open Help, press F1.
*/

        public void Main()
        {
            // TODO: Add your code here
            Dts.TaskResult = (int)ScriptResults.Success;
        }
    }

Script görev projedeki ek proje öğeleri

Komut dosyası görev proje Varsayılandan başka öğeler içerebilir ScriptMain öğe.Projeye, sınıflar, modülleri ve kod dosyaları ekleyebilirsiniz.Ayrıca, madde gruplarını düzenlemek için klasörleri kullanabilirsiniz.Eklediğiniz tüm öğeleri paket içinde bulunurlar.

Script görev projedeki başvuruları

Script görev projedeki sağ tarafından yönetilen derlemeler başvuruları ekleyebilirsiniz Project Explorer, tıklatıp, sonra Add Reference.Daha fazla bilgi için bkz: Komut dosyası çözümleri de diğer derlemeler başvuran.

Not

vsta IDE içinde proje başvuruları görüntülemek Class View veya Project Explorer.Bu pencerelerden birini açın View menü.Gelen yeni bir başvuru ekleyebilir Proje menüsü, dan Project Explorer, ya da Class View.

Komut dosyası görev paketi ile etkileşim

Genel Komut dosyası görev kullanır Dts örnek olan nesne, ScriptObjectModel sınıf ve üyelerine ve içeren paket ile etkileşim kurmak için Integration Services çalışma zamanı.

Aşağıdaki tablo asıl ortak üyelerini listeler ScriptObjectModel sınıfı, kendisi için Script görev kodu aracılığıyla genel maruz Dts nesne.Bu bölümdeki konular, bu üyeler daha ayrıntılı kullanımını tartışın.

Üye

Amaç

[ P:Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel.Connections ]

Paket içinde tanımlanan bağlantı yöneticileri için erişim sağlar.

[ P:Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel.Events ]

Komut dosyası görev hataları, uyarıları ve bilgi iletileri yükseltmek için bir olay arabirim sağlar.

[ P:Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel.ExecutionValue ]

Çalışma zamanı için tek bir nesneyi döndürmek için basit bir yol sağlar (ek olarak TaskResult) de kullanılabilecek iş akışı dallanma için.

[ M:Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel.Log(System.String,System.Int32,System.Byte[]) ]

Görev ilerleme durumu gibi bilgileri kaydeder ve etkin günlüğü sağlayıcıları için sonuçlar.

[ P:Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel.TaskResult ]

Başarı veya başarısızlık görevin raporlar.

[ P:Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel.Transaction ]

Hareket varsa, görevin kapsayıcı içinde çalıştığı sağlar.

[ P:Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel.Variables ]

Listelenen değişkenlerini erişim sağlar ReadOnlyVariables ve ReadWriteVariables Query içinde görev özelliklerini kullanın

The ScriptObjectModel class also contains some public members that you will probably not use.

Üye

Açıklama

[ P:Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel.VariableDispenser ]

The Variables property provides more convenient access to variables.Siz kullanabilirsiniz, ancak VariableDispenser, yöntemleri çaðýrmak gerekir kilit ve kaydınıkilit değişkenleri için okuma ve yazma.Komut dosyası görev işleme kilitleme semantik kullandığınızda, Variables özellik.

Komut dosyası görev hata ayıklama

Script görev, kodda hata ayıklamak için küme en az bir kesme noktası kodu ve sonra Kapat paket çalıştırmak için vsta IDE içinde Business Intelligence Development Studio.Komut dosyası görev paket yürütme girdiğinde vsta IDE yeniden açar ve kodunuzu salt okunur modunda görüntüler.Yürütme, kesme noktası ulaştıktan sonra değişken değerlerini inceleyin ve kalan kod arasında.

Not

Komut dosyası göreviniz hata ayıklama için paket yürütmek gerekir.Yalnızca belirli bir görevi yürütmek, kesme noktaları Script görev kodu içinde sayılır.

Not

paket yürütme görevi çalıştırmak bir alt paketinin bir parçası olarak komut dosyası görevi çalıştırdığınızda, komut dosyası görev hata ayıklaması yapılamıyor.Kesme noktaları, sizin küme bu durumda alt paketindeki komut dosyası görev yoksayıldı.Alt paket normalde ayrı ayrı çalıştırarak ayıklayabilir.

Not

Birden çok komut dosyası görevleri içeren paket hata ayıklama hata ayıklayıcı kesme noktaları tek bir komut dosyası görevi isabetlerinin sayısı ve bir komut dosyası görevleri içinde kesme noktaları göz ardı eder.Bir komut dosyası görevi bir Foreach döngüsü veya döngü için kapsayıcı bir parçası ise, hata ayıklayıcı ilk döngü sonra komut dosyası görev kesme noktalarını yoksayar.

Integration Services simgesi (küçük)Integration Services ile güncel kalın

En son karşıdan yüklemeleri, makaleler, örnekler ve videolarını Microsoftyanı olarak seçilen topluluk çözümleri ziyaret Integration Services sayfa msdn veya TechNet:

Bu güncelleştirmelerle ilgili otomatik bildirim almak için, sayfadaki RSS akışlarına abone olun.