Identity_insert已打开但有错误,但是
使用以下代码,我打开了 Identity_insert 以便能够显式插入一些值:
SET IDENTITY_INSERT dbo.myTable ON
Go
在我的 C# 程序中,身份插入设置为主键而不是 null
,当我想插入一个值时,会生成此错误:
IDENTITY_INSERT 已关闭
,
但我已将其打开,
这是什么问题以及如何解决?
谢谢
With following code,I have identity_insert turned on to be able to insert some value explicitly:
SET IDENTITY_INSERT dbo.myTable ON
Go
the identity insert is set to be primary key and not null
in my c# program,when i want to insert a value,this error is generated:
IDENTITY_INSERT is turned off
but i have turned it on
what's the problem and how to solve it?
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IDENTITY_INSERT
设置仅在当前 SQL 会话中起作用,例如,您无法在 SQL Server Management Studio 中的给定表上打开它,然后对其运行 C# 代码并期望它起作用。您需要做的是让
SET IDENTITY_INSERT dbo.myTable ON
语句成为 C# 应用程序的一部分 - 首先,在命令中将设置设置为 ON,然后从 C# 中执行您需要执行的操作应用程序,最后再次从 C# 代码中关闭该设置。The
IDENTITY_INSERT
setting only works in the current SQL session, e.g. you cannot turn it on on a given table in SQL Server Management Studio and then run your C# code against it and expect it to work.What you need to do is have that
SET IDENTITY_INSERT dbo.myTable ON
statement be part of your C# app - first, set the setting to ON in your command, then do whatever you need to do from your C# app, and in the end, turn off that setting, again, from your C# code.