SQL Server 2005:无效的对象名称异常
在 VS2005 中,我使用访问 SQL Server 的 DLL。 DLL 返回 SQLException
对象名称“tableXYZ”无效
,但 tableXYZ 是数据库中的表。
它应该寻找 dbo.tableXYZ 吗?这是使用的登录名的权限问题吗?
In VS2005, I am using a DLL which accesses a SQL Server. The DLL returns a SQLException
Invalid object name 'tableXYZ'
but tableXYZ is a table in the database.
Should it be looking for dbo.tableXYZ instead? Is this a permissions issue with the login being used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先,您可以打开 SQL Server Profiler 跟踪,以查看 DLL如何连接到数据库。例如,您应该能够看到正在使用哪些凭据。您还可以确认以确保代码连接到正确的数据库等。
As a starting point, you could turn on an SQL Server Profiler trace, to see how the DLL is connecting to the database. e.g. you should be able to see what credentials are being used. You could also confirm to make sure the code is connecting to the right database etc.
这可能是表所有者和权限的问题。
例如,表所有者可能是
dbo
,因此完整的表名称将为dbo.TableXYZ
您连接的用户可能是SQLUser
可能无权访问 dbo 架构。因此只能访问诸如SQLuser.TableXYZ
之类的表我会检查您用于连接到数据库的权限。
This could be an issue with the owner of the tableand permissions.
for example the table owner may be
dbo
so the full table name will bedbo.TableXYZ
The user you connect as, could be for exampleSQLUser
may not have access to thedbo
schema. So can only access tables such asSQLuser.TableXYZ
I'd check the permissions that you use to connect to the database.
使用 dbo.tableXYZ 可以更清楚地显示您想要的内容 - 默认 dbo 架构中的 tableXYZ 。另一种架构中也可能有一个
tableXYZ
- 那么 SQL Server 可能不知道您想要哪一个。这绝对可能是权限问题。如果您以该用户身份连接到 SQL SErver Mgmt Studio 中的该数据库 - 您能看到该
tableXYZ
表吗?更新: DLL 是否需要特定的连接字符串,您可能尚未将其复制到调用应用程序的 app.config 文件中? .NET 中的 DLL 不能真正拥有自己的 mylibrary.dll.config - 默认情况下 .NET 不会读取它。
Using
dbo.tableXYZ
makes it clearer what you want - thetableXYZ
in the defaultdbo
schema. There could be atableXYZ
in another schema, too - then SQL Server might not know which one you want.And it could most definitely be a permissions issue. If you connect to that database in SQL SErver Mgmt Studio as that user - can you see that
tableXYZ
table??UPDATE: does the DLL require a specific connection string, that you might not have copied into your calling app's app.config file?? DLL's in .NET can't really have their own mylibrary.dll.config - it will not be read by .NET by default.
您必须在连接字符串中使用数据库名称 - 否则它只会连接并且您必须使用 dbo.databasename.tableXYZ。
您可以在此处找到各种连接字符串
you have to use the databasename in your connection-string - otherwise it would just connect und you have to use dbo.databasename.tableXYZ.
you can find the various connection-strings here