如何在VS2010数据库项目中从Excel加载测试数据
我正在使用 VS2010 数据库项目,并且希望能够加载:
将数据引用到任何实例(隔离开发、测试等生产)
仅将数据测试到开发和测试数据库中。
据我了解,参考数据没有问题,我将脚本使用到部署后脚本中,该脚本将无条件运行。
对于测试数据,我知道我应该使用数据生成计划;我可以使用数据绑定生成器从数据源(例如 Access、Excel 或文本文件)加载数据。 MSDN 有一个关于从 Excel 电子表格生成测试数据的演练,乍一看看起来像我需要的,但它使用绝对路径来引用 Excel 文件。这似乎与将数据库项目置于源代码管理中不兼容,这些项目由可能在不同位置拥有工作空间的不同用户访问。
在这种情况下加载测试数据的“最佳实践”是什么?我可以在连接字符串中使用相对路径并确保它在所有开发人员计算机上始终以相同的方式解释吗?
我期望找到类似于 |DataDirectory| 的语法替换字符串 允许指定相对于数据库项目目录的路径。
I am using a VS2010 database project, and want to be able to load:
Reference data into any instance (isolated development, test, ... production)
Test data into development and test databases only.
As I understand it, reference data is no problem, I use scripts into a post-deployment script, which will be run unconditionally.
For test data, I understand I should use a data generation plan; and that I can use a data bound generator to load data from a data source such as Access, Excel or a text file. MSDN has a walkthrough on generating test data from an Excel spreadsheet, which at first glance looks like what I need, but it uses an absolute path to reference the Excel file. Which doesn't seem to be compatible with having the database project in source control, accessed by different users who may have their workspaces at different locations.
What is the "best practice" for loading test data in this situation? Can I use a relative path in the connection string and be sure it will always be interpreted in the same way on all developer machines?
I was expecting to find a syntax something like the |DataDirectory| substitution string that would allow a path to be specified relative to the Database Project directory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Excelreader 通过以下链接将 Excel 数据加载到数据集
http://exceldatareader.codeplex.com/
Use the Excelreader to load Excel data to dataset using following link
http://exceldatareader.codeplex.com/
经过进一步阅读,我认为数据生成计划对于这种情况来说是错误的工具。
我现在正在做的是使用测试数据创建一个部署后脚本,然后确保使用 SQL 命令变量有条件地执行它。每个部署目标(隔离开发;UAT;PROD)都可以有自己的SQL命令变量文件(.sqlcmdvars),该文件将控制脚本是否运行。
例如,要仅加载IsolatedDev 数据库的测试数据,我可以在部署后脚本中使用以下内容:
并确保测试数据不会无意中加载到生产数据库中。
请随时加入经验和最佳实践。
On further reading, I think a data generation plan is the wrong tool for this scenario.
What I'm doing now is creating a post-deployment script with the test data, then making sure it is executed conditionally by using SQL command variables. Each deployment target (isolated development; UAT; PROD) can have its own SQL command variables file (.sqlcmdvars), which will control whether the script is run.
E.g. to load test data only for the IsolatedDev database, I can use the following in a post-deployment script:
and be sure the test data won't be inadvertently loaded into a production database.
Please feel free to chime in with experiences and best practices.