我是这个论坛的新手,这是我的第一个帖子,所以我希望我把它发布在正确的位置。
我不知道任何C#,但我知道一些VB,我已经将我的DTS包迁移到SSIS但是我无法使ActiveX脚本工作并决定在脚本任务中重新编写它。我有4个全局变量,它们都已经在全局变量菜单中设置了值。链接到图片:Link。 ActiveX代码在那里,因此用户可以在切换服务器/数据库时更改2个变量,并且它仍然会在那里的表上执行相同的操作(所有表在所有服务器和数据库中具有相同的名称,因此不需要可以调整)并且每天自动运行。这是原始的ActiveX代码:
Function Main()
Dim sEnvironm
Dim sServer
Dim sSourceFile
Dim sSourcePath
Dim sBackupPath
Dim sErrorPath
Dim sFileName
Dim sUDLPath
'*********************************************************
' Set vars
'
' First 2 are depending on the server and db
' FILL IN THE RIGHT VALUES
'
'*********************************************************
sEnvironm = "MON_Datamart"
sServer = "W0254"
' --- DO NOT CHANGE ANYTHING BELOW THIS LINE ---
' ---
sSourceFile = "\\" & sServer & "\Data_sql\" & sEnvironm & "\DTS\SourceFiles\tbl_L47T1.txt"
sSourcePath = "\\" & sServer & "\Data_sql\" & sEnvironm & "\DTS\SourceFiles\"
sBackupPath = "\\" & sServer & "\Data_sql\" & sEnvironm & "\DTS\BackupFiles\"
sErrorPath = "\\" & sServer & "\Data_sql\" & sEnvironm & "\DTS\ErrorFiles\"
sFileName = "tbl_L47T1.txt"
sUDLPath = "\\" & sServer & "\Data_sql\" & sEnvironm & "\UDL\" & sEnvironm & ".udl"
FoundError = False
Set oPackage = DTSGlobalVariables.Parent
Set oConnection = oPackage.Connections("tbl_L47T1.txt")
oConnection.DataSource = sSourceFile
Set oConnection = oPackage.Connections("Datamart")
oConnection.UDLPath = sUDLPath
Set oConnection = oPackage.Connections("Truncate")
oConnection.UDLPath = sUDLPath
Set oTask = oPackage.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask
oTask.SourceObjectName = sSourceFile
oTask.DestinationObjectName = sEnvironm & ".dbo.stg_tbl_L47T1"
DTSGlobalVariables("SourcePath").Value = sSourceFile
DTSGlobalVariables("BackupPath").Value = sBackupPath
DTSGlobalVariables("ErrorPath").Value = sErrorPath
DTSGlobalVariables("FileName").Value = sFileName
Set oTask = Nothing
Set oConnection = Nothing
Set oPackage = Nothing
Main = DTSTaskExecResult_Success
End Function
这就是我到目前为止所做的:
Public Sub Main()
Dim sEnvironm As String
Dim sServer As String
Dim sSourceFile As String
Dim sSourcePath As String
Dim sBackupPath As String
Dim sErrorPath As String
Dim sFileName As String
Dim sUDLPath As String
Dim FoundError As Boolean
Dim oPackage As Object
Dim oConnection As Object
Dim oTask As Object
Dim DTSGlobalVariables As Object
'*********************************************************
' Set vars
'
' First 2 are depending on the server and db
' FILL IN THE RIGHT VALUES
'
'*********************************************************
sEnvironm = "MON_Datamart"
sServer = "W0254"
' --- DO NOT CHANGE ANYTHING BELOW THIS LINE ---
' ---
sSourceFile = "\\" & sServer & "\Data_sql\" & sEnvironm & "\DTS\SourceFiles\tbl_L47T1.txt"
sSourcePath = "\\" & sServer & "\Data_sql\" & sEnvironm & "\DTS\SourceFiles\"
sBackupPath = "\\" & sServer & "\Data_sql\" & sEnvironm & "\DTS\BackupFiles\"
sErrorPath = "\\" & sServer & "\Data_sql\" & sEnvironm & "\DTS\ErrorFiles\"
sFileName = "tbl_L47T1.txt"
sUDLPath = "\\" & sServer & "\Data_sql\" & sEnvironm & "\UDL\" & sEnvironm & ".udl"
FoundError = False
oPackage = Dts.Variables("User::VariableName").Value
oConnection = oPackage.Connections("tbl_L47T1.txt")
oConnection.DataSource = sSourceFile
oConnection = oPackage.Connections("Datamart")
oConnection.UDLPath = sUDLPath
oConnection = oPackage.Connections("Truncate")
oConnection.UDLPath = sUDLPath
oTask = oPackage.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask
oTask.SourceObjectName = sSourceFile
oTask.DestinationObjectName = sEnvironm & ".dbo.stg_tbl_L47T1"
DTSGlobalVariables("SourcePath").Value = sSourceFile
DTSGlobalVariables("BackupPath").Value = sBackupPath
DTSGlobalVariables("ErrorPath").Value = sErrorPath
DTSGlobalVariables("FileName").Value = sFileName
oTask = Nothing
oConnection = Nothing
oPackage = Nothing
Main = DTSTaskExecResult_Success
End Sub
如果我调试这个,我会遇到很多错误,而且我不知道如何修复它们......
错误:
Error: System.Reflection.TargetInvocationException: Het doel van een aanroep heeft een uitzondering veroorzaakt. ---> Microsoft.SqlServer.Dts.Runtime.DtsRuntimeException: The element cannot be found in a collection. This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there.
---> System.Runtime.InteropServices.COMException (0xC0010009): The element cannot be found in a collection. This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there.
bij Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSVariables100.get_Item(Object Index)
bij Microsoft.SqlServer.Dts.Runtime.Variables.get_Item(Object index)
--- Einde van intern uitzonderingsstackpad ---
bij Microsoft.SqlServer.Dts.Runtime.Variables.get_Item(Object index)
bij ST_f32fc12b60f34bebbbdfc0c5e5b40a96.vbproj.ScriptMain.Main()
--- Einde van intern uitzonderingsstackpad ---
bij System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
bij System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
bij System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
bij System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
bij System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
bij System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
bij Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
有人可以帮助我进一步转换吗?我被困住了,不知道如何解决我的错误......
提前致谢!
答案 0 :(得分:0)
我建议您完全删除脚本,而是使用包配置来设置源服务器。然后你只需编辑一个XML文件,而不是实际的包。
这是一个很好的指南:https://www.simple-talk.com/sql/ssis/xml-configuration-files-in-sql-server-integration-services/
只需要记住:不要编辑连接管理器的逻辑名称,而是编辑其中的连接字符串。
我建议你将你的连接管理器重命名为他们真正的目标(即#34;客户系统"如果从客户系统中提取客户),而不是他们指向的服务器(MySQLServerHost \ SQLExpress.DBName),如实际的连接细节将从您的配置中更改。