简体   繁体   English

SSIS自动执行程序包

[英]SSIS automatic package execution

I want to automatically execute my SSIS package once a week at a specified time. 我想每周一次在指定时间自动执行我的SSIS程序包。 I want to clear the entire database before I load the contents of a new excel file every week. 我想在每周加载新的Excel文件的内容之前清除整个数据库。 I think I can use truncate statements for clearing the entire database. 我想我可以使用truncate语句来清除整个数据库。 However, how do I read from a file in which I do not know the name of ahead of time? 但是,如何从不知道提前名称的文件中读取?

My instincts tell me I need to know the following: 我的直觉告诉我,我需要了解以下内容:

How do I prompt the user for a file name in SSIS? 
Am I using VB or C# to do this prompting?

Thanks! 谢谢!

How long of an answer do you want? 您想要多长时间的答案? ;) ;)

How do I read from a file in which I do not know the name of ahead of time? 如何从我不知道提前名称的文件中读取?

You have many options in this regard. 您在这方面有很多选择。 I'm listing them in order that I'd take 我列出他们是为了

  1. My "go to" would be the Foreach Enumerator and use the file type to process the available file(s) in a standard folder. 我的“转到”将是Foreach枚举器,并使用文件类型来处理标准文件夹中的可用文件。 This reduces your problem to a training issue (User, drop file to \\server\\share\\inbound) 这将您的问题减少为培训问题(用户,将文件拖放到\\ server \\ share \\ inbound)

  2. Assuming you have an Expression on the file's Connection Manager ConnectionString property, you can provide a run-time override of this value. 假设您在文件的Connection Manager ConnectionString属性上具有一个Expression,则可以提供此值的运行时替代。 Thus, SSIS variable named InputFile and has a value of \\\\server\\share\\inbound\\source_2012-07-17.txt A Connection Manager named Source and has an expression on the ConnectionString property mapped to @[User::InputFile] When your package runs, as long as the value of InputFile is correct then your package will use the correct source file and all is good. 因此,名为InputFile SSIS变量的值为\\\\server\\share\\inbound\\source_2012-07-17.txt一个名为Source的连接管理器,并且ConnectionString属性上的表达式映射为@ [User :: InputFile]程序包运行,只要InputFile的值正确,则您的程序包将使用正确的源文件,一切都很好。 You don't have to create a variable and use expressiosn to do this, you can do it directly against the connection manager's property but from a maintenance and troubleshooting perspective you'll be better positioned to address issues. 不必创建一个变量,并使用expressiosn要做到这一点,你可以直接做到对连接管理器的属性,但是从你会更好地解决问题维护和故障排除的观点。 When you run the package you will need to use a command-line option to provide an explicit value for the thing you are configuring. 运行软件包时,您将需要使用命令行选项为要配置的事物提供一个明确的值。 Approximately dtexec /file C:\\mypackage.dtsx /set \\Package.Variables[User::InputFile].Properties[Value];"\\\\server\\share\\inbound\\source_2012-07-18.txt" Use the dtexecui to build this string out properly. 大约dtexec /file C:\\mypackage.dtsx /set \\Package.Variables[User::InputFile].Properties[Value];"\\\\server\\share\\inbound\\source_2012-07-18.txt"使用dtexecui构建此字符串正确输出。

  3. If the user is actually running the package (double click, Execute), then it is in running in interactive mode @[System::InteractiveMode] = True There's nothing that prevents you from writing a full-fledged windows form app in a script task as the first step in your package. 如果用户实际上正在运行程序包(双击,执行),则它处于交互模式下运行@[System::InteractiveMode] = True没有什么可以阻止您在脚本任务中编写完整的Windows窗体应用程序作为包装的第一步。 That said, I wouldn't bloat an ETL package with UI code but it can be done. 就是说, 不会用UI代码来夸大ETL包,但是可以做到。 It really depends on what you are attempting to accomplish. 这实际上取决于您要完成的工作。

  4. Move that UI code into a dedicated package. 将该UI代码移到专用程序包中。 After assembling user input, pass that to a child package through parent/child configurations. 组装用户输入后,通过父/子配置将其传递给子包。

  5. This is really just 2 + 3ish. 这实际上只是2 + 3ish。 Do the good thing and make your package run based on a command-line override. 做一件好事,并使您的程序包基于命令行覆盖运行。 That way it works in interactive mode as well as execution on the server (SQL Agent). 这样,它就可以在交互模式下工作,并且可以在服务器(SQL Agent)上执行。 Then use whatever technology you wish to create an interface for acquiring and validating user input and then invoke your package with those values. 然后,使用您希望使用的任何技术创建用于获取和验证用户输入的界面,然后使用这些值调用您的程序包。 You can skip calling DTEXEC and just work with the object model directly. 您可以跳过调用DTEXEC的操作,而直接使用对象模型。

  6. This should really be option eleventy billion. 这确实应该是十亿美元的选择。 The input file will be named \\\\server\\share\\input\\source_file.txt Rule with an iron fist and make your users conform to your will. 输入文件被命名为\\\\server\\share\\input\\source_file.txt带有铁腕的规则,并使您的用户符合您的意愿。 If you have the power, allow the users to use any file name they wish, as long as it's the one you told them to use. 如果有权力,请允许用户使用他们希望的任何文件名,只要它是您告诉他们使用的文件名即可。 Failure to do so will result in their data not being loaded. 否则,将导致其数据无法加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM