SMO 为整个数据库编写脚本,就像 Studio Management 使用生成脚本所做的那样
我正在尝试建立一个 C# 工具来编写从表到存储过程的整个数据库的脚本。我想获取所有架构和数据。我很难在网上找到很多关于如何正确执行此操作的信息。如果您不希望使用备份或传输来实际备份数据库,我认为这将是一种常见的做法作为替代方案,但我找不到太多关于该主题的信息。谁能指导我如何执行此操作或告诉我需要做什么?我已经找到了如何编写表和存储过程的脚本,但我想获取数据库中的所有内容,以便在对数据库的更改破坏其他内容时可以恢复到原来的位置。
我这样做的原因之一是因为我知道如果你进行备份:
a.)它可能会损坏 b.) 您只能在托管 SQL 服务器的服务器上进行备份。如果您从 SQL Server 远程运行应用程序,则无法在本地计算机上备份它。当然,这是假设我不能总是依赖 UNC 路径或任何类型的 ftp 脚本。
I am trying to set up a C# tool that scripts an entire database from the tables down to the stored procedures. I want to get all the schema and data. I am having a hard time finding much on the net on how to do this properly. I would think this would be common practice as an alternative if you don't wish to actually back the dabase up using Backup or Transfer, but I can't find much on the subject. Can anyone direct me to something on how to do this or tell me what needs to be done? I have found how to script Tables and stored procedures, but I want to get EVERYTHING in the database so that I can revert back to where it was if changes to the database breaks other things.
One of the reasons I am going about it this way is because i know that if you do a backup:
a.) it can get corrupt
b.) you can only do a back up on the server hosting the SQL server. You cannot back it up on your local machine if you are running the application remotely from the SQL Server. This is of course assuming that I cannot always rely on a UNC path or ftp script of any kind.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 http://scriptdb.codeplex.com。
这是一个编写数据库 ddl 脚本的工具。
对于编写数据,您可以尝试如下所述的方法: http://sqlblog.com/blogs/ben_miller/archive/2007/10/18/scripting-tables-views-and-data-using-smo-part-3.aspx 或尝试使用 bcp,这对于更大的数据库来说是更好的选择。
Have a look at http://scriptdb.codeplex.com.
This is a tool that scripts out a Database's ddl.
For Scrripting out the data you could try an approach like described here: http://sqlblog.com/blogs/ben_miller/archive/2007/10/18/scripting-tables-views-and-data-using-smo-part-3.aspx or try to use bcp, wich would be the better alternative for bigger databases.