对表使用 sql server 2005 同义词会导致动态查询生成错误
我遇到的情况是,我在服务器 A 上有一个目录,在服务器 B 上有一个相同名称的目录。我在服务器 B 上使用同义词,因此一些表实际上只是通过服务器 A这样
,调用 select * from ServerB.Table 实际上是透明地从 ServerA.Table 返回数据。当我进行选择时,这似乎工作得很好,如果我手动插入 tsql 脚本,这也工作得很好,但是,当我使用 ADO.NET 适配器时,它会给我一个错误,提示“对于 SelectCommand 不支持动态 SQL 生成”不返回任何基表信息。”这通常意味着返回数据时没有可用的主键信息。有什么办法解决这个问题吗? (我最好能够继续使用同义词,因为它实际上并不是排除其使用的选项)。
我知道有一个“ID”列始终是主键,如果需要,我可以将主键信息硬编码回 ado.net 适配器/数据表中。
谢谢!
I have a situation where by i have a catalog on Server A, and a same named Catalog on Server B. I'm using synonyms on Server B so that some tables are actually just going through to server A.
Such that, calling select * from ServerB.Table, is actually returning Data from ServerA.Table transparently. This seems to work fine when i'm doing selects, and also works fine if i hand tsql script inserts, however, when i use the ADO.NET adapter it gives me an error saying " Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information." Which typically means there is no primary key information being made available when the data is returned. Is there any way around this? (With me preferably being able to continue to use the synonym, as it is not really an option to exclude its use).
I know that there is an "ID" column that is always the primary key, and if necessary i can hard code the primary key information back into the ado.net adapter / datatable if required.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用
SQLCommandBuilder
获取用于数据修改操作的SQL
。由于远程表没有返回任何元数据,因此命令生成器无法生成适当的
SQL
来更新或从表中删除,因为它不知道使用哪个字段作为PK
>。您应该为数据适配器提供自己的
UpdateCommand
和DeleteCommand
。请参阅此链接获取代码。
You are using
SQLCommandBuilder
to obtain theSQL
for data modification operations.Since no metadata are returned by the remote table, the command builder cannot generate the appropriate
SQL
for updating or deleting from the table because it does not know which field to use as aPK
.You should provide your own
UpdateCommand
andDeleteCommand
for your data adapter.See this link for the code.