Craig Johnston
Craig Johnston

Reputation: 5563

SQL Server 2005: Invalid object name exception

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?

Upvotes: 2

Views: 4170

Answers (4)

Moe Sisko
Moe Sisko

Reputation: 12015

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.

Upvotes: 0

marc_s
marc_s

Reputation: 754518

Using dbo.tableXYZ makes it clearer what you want - the tableXYZ in the default dbo schema. There could be a tableXYZ 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.

Upvotes: 1

codingbadger
codingbadger

Reputation: 43984

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 be dbo.TableXYZ The user you connect as, could be for example SQLUser may not have access to the dbo schema. So can only access tables such as SQLuser.TableXYZ

I'd check the permissions that you use to connect to the database.

Upvotes: 1

Gambrinus
Gambrinus

Reputation: 2136

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

Upvotes: 0

Related Questions