具有依赖性的SMO Scripter导致一些问题 [英] SMO Scripter with dependencies causing some issues

查看:100
本文介绍了具有依赖性的SMO Scripter导致一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过使用传输对象,现在是smo脚本编写器对象。我们的想法是,我们想要一个脚本来创建数据库。我从脚本编写器对象中得到了我想要的东西,除了有一些问题。



我得到了表,并且依赖于最终的顺序依赖于以下选项:

I've tried to use the transfer object, and now the smo scripter object. The idea is that we would like a script to create the database. I'm getting what I want out of the scripter object, except there are some issues.

I'm getting the tables, and dependencies in the correct order finally with the following options:

scripter.Options.ScriptDrops = false;
scripter.Options.WithDependencies = true;
scripter.Options.Indexes = true;   
scripter.Options.DriAllConstraints = true;   
scripter.Options.IncludeIfNotExists = true;





问题是当我用db.ExecuteNonQuery(脚本)运行脚本时;我收到一个错误:





The problem is when I run the script with db.ExecuteNonQuery(script); I get an error:

Quote:

列已经有一个DEFAULT界限to it.\\ n不能创建约束。请参阅先前的错误。

"Column already has a DEFAULT bound to it.\r\nCould not create constraint. See previous errors."





此行是错误,但我看不到在表创建的脚本中添加任何默认值。



This line is the error, but I don't see any defaults getting added in the script on table create.

ALTER TABLE [dbo].[ChocolatePudding] ADD  DEFAULT ((0)) FOR [IsYummy]
END







有没有我错过的选项或什么?




Is there an option I missed or something?

推荐答案

现在看来快速解决方法是将执行调用更改为:



It looks like a quick way out for now is changing the execute call to:

db.ExecuteNonQuery(script, ExecutionTypes.ContinueOnError);




即使该特定声明没有执行,约束,键等仍然存在。



I认为这是一个可接受的黑客。



Even though that particular statement isn't executing, the restraint(s), key(s), etc are still there.

I consider this an acceptable hack.


这篇关于具有依赖性的SMO Scripter导致一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆