简体   繁体   English

使用VBScript将Active Directory提取到SQL数据库中

[英]Extract Active Directory into SQL database using VBScript

I have written a VBScript to extract data from Active Directory into a record set. 我编写了一个VBScript,用于将Active Directory中的数据提取到记录集中。 I'm now wondering what the most efficient way is to transfer the data into a SQL database. 我现在想知道将数据传输到SQL数据库的最有效方法是什么。

I'm torn between; 我被撕裂了;

  • Writing it to an excel file then firing an SSIS package to import it or... 将其写入excel文件,然后触发SSIS包以导入它或...
  • Within the VBScript, iterating through the dataset in memory and submitting 3000+ INSERT commands to the SQL database 在VBScript中,遍历内存中的数据集并向SQL数据库提交3000+ INSERT命令

Would the latter option result in 3000+ round trips communicating with the database and therefore be the slower of the two options? 后一种选择是否会导致3000多次往返与数据库通信,因此两种选择中的较慢?

Sending an insert row by row is always the slowest option. 逐行发送插入始终是最慢的选项。 This is what is known as Row by Agonizing Row or RBAR. 这就是所谓的Row by Agonizing Row或RBAR。 You should avoid that if possible and take advantage of set based operations. 如果可能,您应该避免这种情况并利用基于集合的操作。

Your other option, writing to an intermediate file is a good option, I agree with @Remou in the comments that you should probably pick CSV rather than Excel if you are going to choose this option. 你的另一个选择,写一个中间文件是一个很好的选择,我同意@Remou在评论中你应该选择CSV而不是Excel,如果你打算选择这个选项。

I would propose a third option. 我会提出第三种选择。 You already have the design in VB contained in your VBscript. 您已经在VBscript中包含了VB中的设计。 You should be able to convert this easily to a script component in SSIS. 您应该能够轻松地将其转换为SSIS中的脚本组件。 Create an SSIS package, add a DataFlow task, add a Script Component ( as a datasource {example here} ) to the flow, write your fields out to the output buffer, and then add a sql destination and save yourself the step of writing to an intermediate file. 创建一个SSIS包,添加一个DataFlow任务,将一个脚本组件( 作为数据源{example here} )添加到流中,将您的字段写入输出缓冲区,然后添加一个sql目标并保存自己写入的步骤一个中间文件。 This is also more secure, as you don't have your AD data on disk in plaintext anywhere during the process. 这也更安全,因为在此过程中,您在任何地方都没有以明文形式存储AD数据。

You don't mention how often this will run or if you have to run it within a certain time window, so it isn't clear that performance is even an issue here. 你没有提到这种情况经常运行的频率,或者你是否必须在某个时间窗口内运行它,因此不清楚性能在这里是否是一个问题。 "Slow" doesn't mean anything by itself: a process that runs for 30 minutes can be perfectly acceptable if the time window is one hour. “慢”并不意味着任何事情:如果时间窗口是一小时,那么运行30分钟的过程是完全可以接受的。

Just write the simplest, most maintainable code you can to get the job done and go from there. 只需编写最简单,最易维护的代码即可完成工作并从那里开始。 If it runs in an acceptable amount of time then you're done. 如果它在可接受的时间内运行,那么你就完成了。 If it doesn't, then at least you have a clean, functioning solution that you can profile and optimize. 如果没有,那么至少你有一个干净,有效的解决方案,你可以分析和优化。

If you already have it in a dataset and if it's SQL Server 2008+ create a user defined table type and send the whole dataset in as an atomic unit. 如果您已经在数据集中拥有它,并且它是SQL Server 2008+创建用户定义的表类型并将整个数据集作为原子单元发送。

And if you go the SSIS route, I have a post covering Active Directory as an SSIS Data Source 如果你去SSIS路线,我有一个帖子覆盖Active Directory作为SSIS数据源

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

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