Kodlama ve kod görev hata ayıklama
Komut yapılandırdıktan sonra içinde 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ı
Script görev kullanır Microsoft Visual StudioAraçları uygulamaları (vsta) komut kendini geliştirme ortamı olarak.
Komut dosyası kodu yazılı Microsoft Visual Basic 2008ya Microsoft Visual C# 2008. Belirttiğiniz komut dosyası dili ayarlayarak ScriptLanguage Emlak Komut dosyası görev Düzenleyicisi. Başka bir programlama dili kullanmak isterseniz, özel bir derleme seçtiğiniz dil geliştirmek ve Script görev kodu işlevleri çağırmanıza.
Script görev oluşturduğunuz komut paket tanımının içinde depolanır. Orada ayrı komut dosyası yok. Bu nedenle, paketi dağıtım Script görev kullanımı etkilemez.
[!NOT]
Paket tasarladığınızda ve komut dosyası hata ayıklama kodu geçici bir proje dosyasına yazılır. Hassas bilgileri bir dosyada saklamak olası bir güvenlik riski olduğundan, komut dosyası kodu şifreleri gibi hassas bilgileri içermeyen öneririz.
Varsayılan olarak, Option StrictIDE içinde devre dışı bırakıldı.
Komut dosyası görev Proje yapısı
Oluşturmak veya bir komut dosyası görevi bulunan komut dosyasını değiştirmek, vsta boş yeni bir proje açılır veya varolan bir projeyi yeniden açar. Bu vsta projedeki yaratılması, dağıtımı paketin etkilemez, çünkü proje içinde paket dosyası kaydedilir; Script görev ek dosyaları oluşturmaz.
Proje öğeleri ve sınıfları Script görev projedeki
Varsayılan olarak vsta Project Explorer penceresinde görüntülenen Script görev projedeki tek bir öğe içeren ScriptMain. ScriptMainMadde, buna da adında tek bir sınıfı içeren ScriptMain. Sınıfındaki kod öğeler Script görev için seçtiğiniz programlama diline bağlı olarak değişiklik gösterebilir:
Ne zaman Script görev yapılandırılmalıdır Visual Basic 2008programlama dili ScriptMainortak bir alt sınıfın var Main. ScriptMain.MainYordam olan Script görev çalıştırıldığında çağıran çalışma yöntemi.
Varsayılan olarak, yalnızca kod Mainyeni bir komut dosyası alt yordamı satır mı Dts.TaskResult = ScriptResults.Success. Bu satır, operasyonda görev başarılı çalışma zamanı bildirir. Dts.TaskResultÖzelliği anlatılan Script görev sonuçları döndürülüyor.
Ne zaman Script görev yapılandırılmalıdır Visual C# 2008programlama dili ScriptMainsınıfın genel bir yöntem var Main. Script görev çalıştığında yöntemi çağrılır.
Varsayılan olarak, Mainyöntemi içeren satırı Dts.TaskResult = (int)ScriptResults.Success. Bu satır, operasyonda görev başarılı çalışma zamanı bildirir.
ScriptMainMadde sınıfları dışındaki içerebilir ScriptMainsınıf Sınıflar sadece içinde bulundukları Script görev için kullanılabilir.
Varsayılan olarak, ScriptMainProje öğesi içeren aşağıdaki kodu autogenerated. Kod şablonu da genel bakış ek bilgi ve Script görev almak ve SSIS, değişkenler, olaylar ve bağlantılar gibi nesnelerle sağlar.
' 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 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;
}
}
/*
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;
}
}
Script görev projedeki ek proje öğeleri
Script görev projedeki varsayılandan başka öğeler içerebilir ScriptMainMadde. Proje dersleri, modülleri ve kod dosyaları ekleyebilirsiniz. Madde gruplarını düzenlemek için klasörleri'ni de kullanabilirsiniz. Eklediğiniz tüm öğeleri paketi içinde kalıcı.
Script görev projedeki başvuruları
Script görev projedeki sağ tarafından yönetilen derlemeler başvuruları ekleyebilirsiniz Project Explorerve o zaman tıkırtı Add Reference. Daha fazla bilgi için, bkz. Komut dosyası çözümleri diğer derlemeler başvuran.
[!NOT]
Sen-ebilmek görüş proje başvuruları vsta IDE içinde Class View veya Project Explorer. Bu pencerelerden birini açın View menü. Sen-ebilmek eklemek yeni başvuru Proje menüsü, dan Project Explorer, veya Class View.
Script görev paketi ile etkileşim
Script görev küresel kullanır Dtsnesnesinin bir örneği, ScriptObjectModelsınıf ve üyelerinin içeren paketin ve ile etkileşim için Integration Servicesçalışma.
Asıl kamu üyeleri aşağıdaki tabloda ScriptObjectModelsınıf, hangi Script görev kodu ile global maruz Dtsnesne. Bu bölümdeki konular ayrıntılı bu üyelerin kullanımını tartışın.
Üye |
Amaç |
---|---|
Paket içinde tanımlanan bağlantı yöneticileri için erişim sağlar. |
|
Hataları, uyarıları ve bilgi iletileri yükseltmek Script görev için olayları arabirim sağlar. |
|
Çalışma Zamanı için tek bir nesneyi döndürmek için basit bir yol sağlar (ek olarak TaskResult) de kullanılabilir iş akışı branching için. |
|
Görev ilerleme durumu gibi bilgileri kaydeder ve etkin günlüğü sağlayıcıları için sonuçlar. |
|
Başarı veya başarısızlık görevin raporlar. |
|
Hareket varsa, görevin kapsayıcı içinde çalıştığı sağlar. |
|
Değişkenleri içinde listelenen erişim sağlar ReadOnlyVariablesve ReadWriteVariablesJavaScript içinde görev özelliklerini kullanma |
ScriptObjectModelSınıfı, muhtemelen kullanacağı ortak bazı üyeleri de içerir.
Üye |
Açıklama |
---|---|
VariablesÖzelliği değişken daha kolay erişim sağlar. Her ne kadar sen-ebilmek kullanma VariableDispenser, kilitlemek ve kilidini açmak için okuma ve yazma değişkenleri için yöntemler açıkça çağırmalısınız. Script görev işleme kilitleme semantiği için kullandığınızda Variablesözellik. |
Kod görev hata ayıklama
Script görev kodu hata ayıklamak için kod içinde en az bir kesme noktası ayarlamak ve paketi çalıştırmak için vsta IDE kapatın SQL Server Veri Akışı Araçları (SSDT). Paketi yürütme Script görev girdiğinde vsta IDE yeniden açar ve kodunuzu salt okunur modunda görüntüler. Sonra yürütme, kesme noktasına ulaştığında, değişken değerlerini inceleyebilir ve kalan kod adım.
Dikkat |
---|
Paketi 64-bit modunda çalıştırdığınızda kod görev hata ayıklama. |
[!NOT]
, Kod görev hata ayıklama için paketi yürütme gerekir. Yalnızca tek tek görevi yürütmek, kesme noktaları Script görev kodu sayılır.
[!NOT]
Bir alt paketi yürütme paketi görev çalıştırılan bir parçası olarak Script görev çalıştırıldığında bir kod görev hata ayıklama olamaz. Çocuk paket Script görev ayarlamak kesme noktaları bu durumlarda göz ardı. Ayrıca çalıştırarak alt paketi normalde hata.
[!NOT]
Birden fazla komut dosyası görev içeren bir paket hata ayıklarken, bir kod görev hata ayıklayıcı Için debugs gösterir. Hata ayıklayıcı tamamlarsa, durumda bir Foreach döngüsü veya döngü için kapsayıcı olarak sistem başka bir kod görev hata ayıklama.
Dış Kaynaklar
- Blog girişi, vsta kurulum ve yapılandırma sorunları SSIS 2008 ve 7 yüklemelerinde, blogs.MSDN.com üzerinde.
|
Ayrıca bkz.
Başvuru
Komut dosyası çözümleri diğer derlemeler başvuran
Komut dosyası görev Düzenleyicisi'nde Script görev yapılandırma