Как мне назвать DTS из приложения VB.net?Как я могу назвать пакет DTS SQL Server 2000 в VB.net
ответ
Если вы имеете в виду Data Transformation Service s, который является частью SQL Server 2000 (недоступно в более поздней версии, поскольку оно было заменено услугами интеграции), существует несколько способов.
Вы можете запустить его из DTSRun, если ваше приложение на сервере с помощью Process.Start
process.start("dtsrun /S ""server name"" /U sa /N ""d:\task.dts""")
Если это не на сервере вы можете использовать DTSRun но внутри хранимой процедуры, которые вы вызываете с помощью мастера .dbo.xp_cmdshell, Затем вызовите SP в свой код. (Хотя, если вы используете xp_cmdshell, вы должны знать об угрозах безопасности при открытии).
В качестве альтернативы вы можете посмотреть на этой статье объясняется, как это сделать из VB Script, но код может быть легко преобразован .:
https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5164094.html
Это довольно сырой набор классов, которые должны делать то, что вы хотите, если хотите программный контроль над пакетом DTS от VB.Net. Я не гарантирую правильность или надежность, но он должен дать вам достаточно указателей, чтобы начать работу.
Просто добавьте ссылку на библиотеку DTSPackage объектов (COM) для вашего визуального проекта студии
Option Explicit On
Option Strict On
Импорт DTS Импорт System.Runtime.InteropServices
пространство имен Test Публичный класс DTSRunner Частный cpPoint как ComTypes.IConnectionPoint Частный cpContainer As ComTypes.IConnectio nPointContainer Private intCookie As Integer Частные ПЭС Как PackageEventsSink
Public Sub RunPackage(ByVal packageName As String)
Dim pkg As New DTS.PackageClass
pkg.LoadFromSQLServer("MySQLServer", String.Empty, String.Empty, DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection, String.Empty, String.Empty, String.Empty, PackageName, System.Reflection.Missing.Value)
cpContainer = CType(pkg, ComTypes.IConnectionPointContainer)
cpContainer.FindConnectionPoint(New Guid("10020605-EB1C-11CF-AE6E-00AA004A34D5"), cpPoint)
PES = New PackageEventsSink
cpPoint.Advise(PES, intCookie)
AddHandler PES.OnPackageOnError, AddressOf PackageErroredHandler
AddHandler PES.OnPackageOnQueryCancel, AddressOf PackageQueryCancelHandler
pkg.Execute()
If cpPoint IsNot Nothing Then
cpPoint.Unadvise(intCookie)
End If
If Not pkg Is Nothing Then
pkg.UnInitialize()
End If
If PES IsNot Nothing Then
RemoveHandler PES.OnPackageOnError, AddressOf PackageErroredHandler
RemoveHandler PES.OnPackageOnQueryCancel, AddressOf PackageQueryCancelHandler
End If
PES = Nothing
cpContainer = Nothing
cpPoint = Nothing
pkg = Nothing
End Sub
Private Sub PackageErroredHandler(ByVal sender As Object, ByVal e As DTSEventArgs)
If Not packageErrored Then
TraceEvent(TraceEventType.Error, -1, _
"Error In DTS Package : {1} - {2} - {3} - {4}", _
.EventSource, e.ErrorCode, e.Source, e.Description)
packageErrored = True
End If
e.Cancel = False
End Sub
Private Sub PackageQueryCancelHandler(ByVal sender As Object, ByVal e As DTSEventArgs)
e.Cancel = False
End Sub
Private Class DTSEventArgs
Inherits EventArgs
Public EventSource As String
Public ErrorCode As Integer
Public Source As String
Public Description As String
Public Cancel As Boolean
Public PercentComplete As Integer = 0
Public Sub New(ByVal EventSource As String, ByVal Source As String, ByVal Description As String, ByVal ErrorCode As Integer, ByVal Cancel As Boolean)
Me.EventSource = EventSource
Me.Source = Source
Me.Description = Description
Me.ErrorCode = ErrorCode
Me.Cancel = Cancel
End Sub
End Class
Private Delegate Sub PackageOnErrorEventHandler(ByVal sender As Object, ByVal e As DTSEventArgs)
Private Delegate Sub PackageOnFinishEventHandler(ByVal sender As Object, ByVal e As DTSEventArgs)
Private Delegate Sub PackageOnStartEventHandler(ByVal sender As Object, ByVal e As DTSEventArgs)
Private Delegate Sub PackageOnProgressEventHandler(ByVal sender As Object, ByVal e As DTSEventArgs)
Private Delegate Sub PackageOnQueryCancelEventHandler(ByVal sender As Object, ByVal e As DTSEventArgs)
Private Class PackageEventsSink
Implements DTS.PackageEvents
Public Event OnPackageOnError As PackageOnErrorEventHandler
Public Event OnPackageOnFinish As PackageOnFinishEventHandler
Public Event OnPackageOnStart As PackageOnStartEventHandler
Public Event OnPackageOnProgress As PackageOnProgressEventHandler
Public Event OnPackageOnQueryCancel As PackageOnQueryCancelEventHandler
Overridable Overloads Sub OnError(ByVal EventSource As String, _
ByVal ErrorCode As Integer, ByVal Source As String, _
ByVal Description As String, ByVal HelpFile As String, _
ByVal HelpContext As Integer, ByVal IDofInterfaceWithError As String, _
ByRef pbCancel As Boolean) Implements DTS.PackageEvents.OnError
Dim e As New DTSEventArgs(EventSource, Source, Description, ErrorCode, pbCancel)
TraceEvent(TraceEventType.Verbose, 0, String.Format(" OnError in {0}; ErrorCode = {1}, Source = {2}, Description = {3}, HelpFile = {4}, HelpContext = {5}, IDofInterfaceWithError = {6}", EventSource, ErrorCode, Source, Description, HelpFile, HelpContext, IDofInterfaceWithError))
RaiseEvent OnPackageOnError(Me, e)
pbCancel = e.Cancel
End Sub
Overridable Overloads Sub OnFinish(ByVal EventSource As String) Implements DTS.PackageEvents.OnFinish
Dim e As New DTSEventArgs(EventSource, String.Empty, "Execution Finished", 0, False)
TraceEvent(TraceEventType.Verbose, 0, String.Format(" OnFinish in {0}", EventSource))
RaiseEvent OnPackageOnFinish(Me, e)
End Sub
Overridable Overloads Sub OnProgress(ByVal EventSource As String, _
ByVal ProgressDescription As String, ByVal PercentComplete As Integer, _
ByVal ProgressCountLow As Integer, ByVal ProgressCountHigh As Integer) _
Implements DTS.PackageEvents.OnProgress
Dim e As New DTSEventArgs(EventSource, String.Empty, ProgressDescription, 0, False)
e.PercentComplete = PercentComplete
TraceEvent(TraceEventType.Verbose, 0, String.Format(" OnProgress in {0}; ProgressDescription = {1}, PercentComplete = {2}, ProgressCountLow = {3}, ProgressCountHigh = {4}", EventSource, ProgressDescription, PercentComplete, ProgressCountLow, ProgressCountHigh))
RaiseEvent OnPackageOnProgress(Me, e)
End Sub
Overridable Overloads Sub OnQueryCancel(ByVal EventSource As String, ByRef pbCancel As Boolean) Implements DTS.PackageEvents.OnQueryCancel
Dim e As New DTSEventArgs(EventSource, String.Empty, String.Empty, 0, pbCancel)
TraceEvent(TraceEventType.Verbose, 0, String.Format(" OnQueryCancel in {0}; pbCancel = {1}", EventSource, pbCancel))
RaiseEvent OnPackageOnQueryCancel(Me, e)
pbCancel = e.Cancel
End Sub
Overridable Overloads Sub OnStart(ByVal EventSource As String) Implements DTS.PackageEvents.OnStart
Dim e As New DTSEventArgs(EventSource, String.Empty, "Execution Started", 0, False)
TraceEvent(TraceEventType.Verbose, 0, String.Format(" OnStart in {0}", EventSource))
RaiseEvent OnPackageOnStart(Me, e)
End Sub
End Class
#End Region
End Class
End Namespace
Что такое DTS? Не могли бы вы быть более подробными? –
DTS = Служба преобразования данных (используется в SQL Server Enterprise Manager) – sef