lcc
lcc

Reputation: 185

how to query a table in a Catalog - schema - table structure?

I have a catalog called TEKLABEL, a schema called PUB, a table called MstrShip

when I try to query the table I used

from PUB.MstrShip

and system gives me error : Invalid Object Name "PUB.MstrShip"

How can I query that table then?

Background: I'm working on a very old windows server 2003 SP2 and SQL server is old too (SQL Query Analyzer Ver. 8.00.2039). When I use the ODBC Query Tool v1.38 to query the tables, I used "PUB.MstrShip" it can execute and give me results. But when I want to run a test program with "PUB.MstrShip" specified in the program, it would report error "Invalid Object Name 'PUB.MstrShip'"

enter image description here This is the SQL query analyzer connection string

enter image description here This is the program connection string in config file

enter image description here This is the structure

Upvotes: 0

Views: 500

Answers (2)

JamieA
JamieA

Reputation: 2013

Try amending your connection string to connect to the teklable database, that should only be one manual change in your program. eg

"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog=TEKLABLE;UserId=Your_Username;Password=Your_Password;" 

Looking at your connection properties, I would advise trying the suggestion of tgolisch and change the default database for the sqluser login to be teklable

Which version of SQL Server are you using? If you connect to the server using SSMS, and go to Security > Logins , then you can edit the properties for the SQLuser login, and change the default database.

It may be worth checking that no other applications use this login, as your change could break them. A better option could be to create a new login called TEKLABELuser, and set the default database to be teklable

Upvotes: 2

tgolisch
tgolisch

Reputation: 6744

In SQL Server, you can specify the default catalog for your login(s) to be TEKLABEL. Then your queries should work as-is. Otherwise, you could specify it in your connection strings, as JamieA has shown.

Upvotes: 2

Related Questions