简体   繁体   English

如何在字段名称中使用句点创建到SQL Server视图的Jet ODBC链接?

[英]How do I create a Jet ODBC link to a SQL Server view with periods in the field names?

I need to create an ODBC link from an Access 2003 (Jet) database to a SQL Server hosted view which contains aliased field names containing periods such as: 我需要创建一个从Access 2003(Jet)数据库到SQL Server托管视图的ODBC链接,该视图包含带句点的别名字段名称,例如:

Seq.Group

In the SQL source behind the view, the field names are encased in square brackets... 在视图后面的SQL源中,字段名称用方括号括起来...

SELECT Table._Group AS [Seq.Group]

...so SQL Server doesn't complain about creating the view, but when I try to create an ODBC link to it from the Jet DB (either programmatically or via the Access 2003 UI) I receive the error message: ...因此SQL Server不会抱怨创建视图,但是当我尝试从Jet DB创建到该视图的ODBC链接时(通过编程方式或通过Access 2003 UI),我收到错误消息:

'Seq.Group' is not a valid name. 'Seq.Group'不是有效的名称。 Make sure that it does not include invalid characters or punctuation and that it is not too long. 确保它不包含无效字符或标点符号,并且时间不要太长。

Unfortunately, I cannot modify the structure of the view because it's part of another product, so I am stuck with the field names the way that they are. 不幸的是,我不能修改视图的结构,因为它是另一种产品的一部分,所以我一直以字段名称的方式来保留它们。 I could add my own view with punctuation-free field names, but I'd really rather not modify the SQL Server at all because then that becomes another point of maintenance every time there's an upgrade, hotfix, etc. Does anyone know a better workaround? 可以使用无标点符号的字段名添加自己的视图,但是我真的不希望完全修改SQL Server,因为那样的话,每次升级,修复程序等时,这都会成为另一个维护点。有人知道更好的解决方法吗? ?

Although I didn't technically end up escaping the dot, your suggestion actually did make me realize another alternative. 尽管从技术上讲,我并没有最终摆脱困境,但您的建议实际上确实使我意识到了另一种选择。 While wondering how I would "pass" the escape code to the "SQL" server, it dawned on me: Why not use a "SQL Pass-Through Query" instead of an ODBC linked table? 在想知道如何将转义代码“传递”到“ SQL”服务器时,它突然出现:为什么不使用“ SQL传递查询”而不是ODBC链接表? Since I only need read access to the SQL Server data, it works fine! 由于我只需要对SQL Server数据的读取访问权限,因此可以正常工作! Thanks! 谢谢!

Just guessing here: did you try escaping the dot? 只是在这里猜测:您是否尝试过将点转义? Something like "[Seq\\.Group]"? 类似于“ [Seq \\ .Group]”?

Another proposal would be to add a new view on your sql server, not modifying the existing one. 另一建议是在sql服务器上添加新视图,而不修改现有视图。 Even if your initial view is part of a "solution", nothing forbids you of adding new views: 即使您的初始视图是“解决方案”的一部分,也没有什么可以阻止您添加新视图的:

SELECT Table._Group AS [Seq_Group]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM