Java/MSSQL: java.sql.SQLException 无效的对象名称 'TableName'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/909599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java/MSSQL: java.sql.SQLException Invalid object name 'TableName'
提问by DrStalker
I'm trying to move a java application from an old server to a new server. The application runs on Tomcat, uses Microsoft SQL Server as the backend DB, and used a system DSN defined in Data Sources (ODBC) to decide where to connect to. The old server used Windows 2000/SQL server 2000, the new server uses Windows 2003/SQL Server 2005.
我正在尝试将 Java 应用程序从旧服务器移动到新服务器。该应用程序在 Tomcat 上运行,使用 Microsoft SQL Server 作为后端 DB,并使用数据源 (ODBC) 中定义的系统 DSN 来决定连接到何处。旧服务器使用Windows 2000/SQL Server 2000,新服务器使用Windows 2003/SQL Server 2005。
The ODBC definition is identical between servers, and defines the DB to use.
服务器之间的 ODBC 定义是相同的,并且定义了要使用的 DB。
On the new server when a user tries to login the following appears in the stdout.log:
在新服务器上,当用户尝试登录时,stdout.log 中会出现以下内容:
user is being checked Error: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'UserTable'.
正在检查用户 错误:java.sql.SQLException:[Microsoft][ODBC SQL Server 驱动程序][SQL Server]无效的对象名称“UserTable”。
A table called UserTabledoes exist in the DB, but shows as "dbo.USerTable" through the management interface.
数据库中确实存在名为UserTable的表,但通过管理界面显示为“ dbo.USerTable”。
Is there a setting somewhere in MSSQL I should be adjusting to make it happy with the "dbo." prefix being missing, or is there something else I've missed?
MSSQL 中是否有某个设置我应该调整以使其对“dbo”感到满意。前缀丢失了,还是我错过了其他东西?
[edit] Windows authentication is used, and the Public and Guest roles have been given full rights to the DB as a troubleshooting step.
[编辑] 使用 Windows 身份验证,作为故障排除步骤,公共和访客角色已被授予对数据库的完全权限。
回答by Gandalf
Are the DB logins different? the dbo "prefix" is just the schema that the object is defined under. So if your ODBC connector is using the dbo credentials to login that object should be in it's default schema.
数据库登录是否不同?dbo“前缀”只是对象在其下定义的模式。因此,如果您的 ODBC 连接器使用 dbo 凭据登录该对象,则该对象应该在其默认架构中。
回答by Jon Skeet
Do you have to use ODBC in the first place? In my experience the "native" (type 4) SQL Server drivers are better. There's a Microsoft driverand jTDS. I don't have much experience with the MS driver, but the jTDS one is good.
您是否必须首先使用 ODBC?根据我的经验,“本机”(类型 4)SQL Server 驱动程序更好。有一个Microsoft 驱动程序和jTDS。我对 MS 驱动程序没有太多经验,但 jTDS 驱动程序很好。
Of course, if you're forced to use ODBC by other factors, this won't be any use to you - but if you have the option, it would be worth a try. It would be one fewer thing to configure on the Windows box.
当然,如果您因其他因素而被迫使用 ODBC,这对您没有任何用处 - 但如果您有选择,那么值得一试。在 Windows 机器上配置少一件事。

