java 无效的对象名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6647846/
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
Invalid object name
提问by david99world
When doing...
当做...
select * from students
I get a "Invalid object name" error. Basically, I think I can see the problem in that the tables are prefixed with an object name rather than just dbo, lets call the schema "test".
我收到“无效的对象名称”错误。基本上,我认为我可以看到问题在于表以对象名称为前缀,而不仅仅是 dbo,让我们将模式称为“测试”。
So this means....
所以这意味着……
select * from test.students
The problem I have is that I can't change the SQL code (it's in release, long story) or change the tables. My question is, is there anything I can change in SQL server that will allow me to connect say with a specific SQL server user so I can still run my queries as...
我遇到的问题是我无法更改 SQL 代码(它在发布中,长篇大论)或更改表。我的问题是,在 SQL Server 中是否有任何我可以更改的内容可以让我连接到特定的 SQL Server 用户,这样我仍然可以将查询作为...
select * from students
Omitting the object name, but still have the object name against the table? I can add another SQL user or something like that no problem.
省略了对象名称,但仍然有对表的对象名称?我可以添加另一个 SQL 用户或类似的东西,没问题。
I'm using Java over the jdbc protocol, so my connection string is something like jdbc:sqlserver://hostname:port;databaseName=db;user=myuser;password=mypassword
我通过 jdbc 协议使用 Java,所以我的连接字符串类似于 jdbc:sqlserver://hostname:port;databaseName=db;user=myuser;password=mypassword
Thanks,
谢谢,
David
大卫
回答by Ben Thul
You're looking for a default schema option, which doesn't exist for a given connection. That is to say that you can't say something like "until I say otherwise, unqualified tables are in the test schema". You can, however, set a default schema for a user. For your example, you'd do
您正在寻找默认模式选项,该选项对于给定连接不存在。也就是说,您不能说“除非我另有说明,否则不合格的表在测试模式中”。但是,您可以为用户设置默认架构。对于你的例子,你会做
alter user [myuser] with default_schema = [test]
回答by Atzoya
Try to edit the connection string and set your default catalog to your "test" database
尝试编辑连接字符串并将默认目录设置为“测试”数据库
<add name="ConnectionString" connectionString="Data Source=server;Initial
Catalog=test;Persist Security Info=True;User ID=user;Password=password;"
providerName="SqlDataClient"/>