Kodlama ve kod görev hata ayıklama

Yapılandırma komut dosyası görev sonraKomut dosyası görev Düzenleyicisi, özel kod yazdığınız Script görev geliştirme ortamı.

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., Belirttiğiniz komut dosyası dili olarakScriptLanguageKod görev Düzenleyicisiözelliğinde.Başka bir programlama dili kullanmak isterseniz, özel bir derleme seçeneği dilinizde geliştirme ve görev komut dosyası kodundan işlevselliğini arayın.

Komut dosyası kod görev oluşturduğunuz paket tanımının içinde depolanır.Ayrı komut dosyası yok.Bu nedenle, paket dağıtım komut dosyası Görev Kullanımı etkilemez.

Not

Paketin tasarımı 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ğu için komut dosyası kodu içinde parola gibi duyarlı bilgileri içermeyen öneririz.

Varsayılan olarak,Option Strictdevre dışı IDE.

Komut dosyası görev proje yapısı

Bir komut dosyası görevi içeren komut dosyası oluşturduğunuzda veya VSTA boş yeni bir proje açar veya varolan projeyi yeniden açar.Paket dosyası projeye kaydedilen için bu VSTA Proje oluşturulması paketin dağıtımını etkilemez; kod görev ek dosyaları oluşturmaz.

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

Varsayılan olarak, VSTA Project Explorer penceresinde görüntülenen komut dosyası görev projesini içeren tek bir öğeScriptMain.The ScriptMain item, in turn, contains a single class, also named ScriptMain.Sınıfındaki kod öğeler kod görev için seçtiğiniz programlama dilini bağlı olarak farklılık gösterir:

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

    Varsayılan olarak, yalnızca koddaMainYeni bir komut dosyasının alt satırı iseDts.TaskResult = ScriptResults.Success.Bu satırı çalışma zamanı, görevin kendi işlem başarılı olduğunu bildirir.The Dts.TaskResult property is discussed in Komut dosyası görevden sonuçları döndürülüyor.

  • , Script görev için yapılandırılmışVisual C# 2008programlama dili,ScriptMainsınıfın genel bir yöntem varMain.Komut dosyası belirtir yöntem çağrılır.

    Varsayılan olarak,MainYöntem içeren satırıDts.TaskResult = (int)ScriptResults.Success.Bu satırı çalışma zamanı, görevin kendi işlem başarılı olduğunu bildirir.

The ScriptMain item can contain classes other than the ScriptMain class.İçinde bulundukları yalnızca komut dosyası göreve sınıfları vardır.

Varsayılan olarak,ScriptMainProje öðesi içeren aşağıdaki autogenerated kodu:

' 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=AdventureWorks;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=AdventureWorks;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;
        }
    }

Komut dosyası görev projenin ek Project Items

The Script görev proje varsayılandan başka öğeler içerebilirScriptMainöğe.Projeye, sınıf modülleri ve kod dosyaları ekleyebilirsiniz.Madde gruplarını düzenlemek için klasörleri'ni de kullanabilirsiniz.Eklediğiniz tüm öğeleri, paket içinde kalıcı.

Komut dosyası görev proje başvuruları

Yönetilen derlemeleri sağ tıklatıp komut görevin proje başvuru ekleyebilirsinizProject Explorerve sonra Add Reference . Daha fazla bilgi için bkz:Diğer derlemeler komut dosyası kullanan Solutions, başvuran.

Not

Proje başvuruları VSTA IDE içinde görüntüleyebilirsinizClass ViewProject Exploreriçinde veya.Bu pencerelerden birini açınGörünüm menu.Yeni bir başvuru ekleyebilirProjeProject Explorerveya Class View menüsünden.

Komut dosyası görev paket ile etkileşim

The Script görev genel kullanırDtsörnek olan bir nesne,ScriptObjectModelsınıfı ve üyelerine ve içeren paketin ile etkileşim kurmak içinIntegration Servicesçalışma zamanı.

Asıl ortak üyeleri aşağıdaki tabloda listelenmektedirScriptObjectModelsınıf, genel komut dosyası görev kodu için açıkDtsnesne.Bu bölümdeki konular, kullanımı, bu üyeler daha ayrıntılı olarak ele almaktadır.

Üye

Amaç:

Connections()

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

Events()

Komut dosyası görev hataları, uyarıları ve bilgi iletileri oluşturmak için bir olay arabirim sağlar.

ExecutionValue()

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

Log(String, Int32, array<Byte[])

Görev ilerleme durumu gibi bilgileri kaydeder ve etkin günlük sağlayıcılarına olur.

TaskResult()

Başarılı veya başarısız görevin bildirir.

Transaction()

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

Variables()

Listelenen değişkenleri erişim sağlayanReadOnlyVariablesveReadWriteVariablesgörev özelliklerini kullanmak komut içinde

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

Üye

Açıklama

VariableDispenser()

The Variables() property provides more convenient access to variables.Kullanabilirsiniz, ancakVariableDispenser()size gereken açıkça arayın kilitlemek ve kilidini açmak için okuma ve değişkenleri yöntemleri yazma.The Script görev işleme kilitleme mantığı, kullandığınızVariables()özellik.

Komut dosyası görev hata ayıklama

Komut dosyası göreviniz kod hata ayıklamasını kodda, en az bir kesme noktası ayarlamak ve paket çalıştırmak için VSTA IDE kapatınBusiness Intelligence Development Studio.Paket yürütme kod görev girdiğinde, VSTA IDE yeniden açar ve salt okunur modda kodunuzu görüntüler.Yürütme, kesme noktası noktası ulaştıktan sonra değişken değerlerini inceleyin ve kalan kod boyunca adım.

Not

Komut dosyası göreviniz hata ayıklamak için paket yürütmelisiniz.Yalnızca tek tek görevi yürütmek, komut dosyası kodu içinde kesme noktalarını göz ardı edilir.

Not

Bir yürütmek paket görevden çalıştırılan bir alt paketinin bir parçası olarak komut dosyası görevi çalıştırdığınızda, komut dosyası göreve hata ayıklama olamaz.Alt paketindeki komut dosyası görev ayarladığınız kesme bu durumlarda gözardı.Ayrı ayrı çalışan alt paket normal hata.

Not

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

Integration Services icon (small)tümleştirme Services ile güncel kalın

En son karşıdan yüklemeler, makaleler, örnekler, Microsoft Office 2010 Suite gelen video yanı sıra, seçilen topluluk çözümleri için ziyaret edin veIntegration ServicesMSDN veya TechNet sayfa:

Bu güncelleştirmeler otomatik bildirilmesi için sayfanın RSS akışlarını için abone olmak olun.