Invalid Object Name in mssql 2005 - sql-server-2005

We currently have an issue with our MSSQL 2005 database. We've recently undergone a migration from windows server 2003 to 2008. SQL Server has remained as 2005. I'm using SQL Server Management Studio to work on.
All the tables in the database follow the format: [SCHEMA].[TABLE_NAME]
When I enter the SQL:
SELECT * FROM [table_name]
I get the error message: Invalid object name '[table_name]'.
If I type in:
SELECT * FROM [schema].[table_name]
This works fine. The username we log into the database with owns the schema which is prepended to all the table names.
The problem is, we have 3rd party companies which have software which exports data from the database. 2 companies have now tried to run their exporters, however are getting the error 'Invalid object name'. The software is logging in with the username which owns the schema.
My question is exactly the same as this one I've found on the internet:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=99802
However the answer on that question seems to be full of keywords rather than actual sentences which makes it very hard to understand.
If anyone could help, it'd be greatly appreciated.
Many thanks
Phil

Set the default schema for the 3rd party's username to the schema their un-prefixed references should point to:
ALTER USER foo WITH DEFAULT_SCHEMA = [bar];
(This is different from owning the schema.)
And tell them to write software correctly. In SQL Server you should always be specifying the schema name, even if you always use dbo.

Related

Ignoring schema name on sql select?

using SQL server 2014 I am able to select without specifying the schema name when it is NOT DBO.
We are now switching over to SQL 2016 and I am no longer able to select without adding the schema name?
Problem: Going back into each stored proc to add the schema name in would take a lot of time so I was wondering if it is possible to ignore the schema name somehow? I have been searching google but haven't found anything..
The procs are used in our SSRS reports, which there are over 100 and some are embedded into the reports so if there is a way to avoid having to change each one that would be great!
It seems the default schema is a property of the connecting user. Maybe you should check how the new "migrated" user has been defined.

Microsoft Access 2007 - How to Change Path to Database

I have been asked to make some changes to an Access database used by a local company. The database is on a server and is in Access 2003 format (mdb). The company is using Access 2007. The previous programmer is no longer available and there is very little documentation. Now, I copied the database (delta.mdb) and the back-end database (delta_be.mdb) to my computer at home so I can work on it. When I run the database the following error message appears:
"//deltamain/orderprogram/delta_be.mdb" is not a valid path. I then went into VBA and searched for references to "delta_be.mdb" so I could change the path. But I could not find any references.
Question 1 - Can someone tell me where the path to the back-end database is stored? Perhaps it's a property of the database? I can't find it anywhere.
Question 2- Is there a way to print a list of the names of all the objects in the database. I don't want to analyze the objects, just print the names.
Thank you!
Question 1 - Can someone tell me where the path to the back-end database is stored? Perhaps it's a property of the database? I can't find it anywhere.
Answer 1 : eexternal links or Path are stored in the MsysObjects system table in the database.
Below sql will give all the linked table name and Connect(link to backend)
SELECT MsysObjects.Name, MsysObjects.Connect
FROM MsysObjects
WHERE (((MsysObjects.Connect) Is Not Null));
Question 2- Is there a way to print a list of the names of all the objects in the database.
Answer 2: Below sql will give you all the user and system object on the Database.
SELECT * FROM MsysObjects

Multiple Schema Permissions In SQL Server 2008 R2

We are migrating a database from SQL Server 2000 to SQL Server 2008 R2 and have run into a problem with our schemas. In SQL Server 2000, if you didn't prefix your object names with a owner/schema (e.g. SELECT * FROM blah rather than dbo.blah) SQL Server would still figure it out. This worked even if your object was in a non-dbo owner.
In SQL Server 2005 this was changed as described here: http://blogs.msdn.com/b/mssqlisv/archive/2007/03/23/upgrading-to-sql-server-2005-and-default-schema-setting.aspx.
I can get around a database having 2 schemas by making a user's default schema xyz instead of dbo. The problem I run into is in a database where there is a 3rd schema (abc.blah). When I make the users default xyz, they can get to dbo without a hitch but get an Invalid Object error when trying to select something from abc without a schema prefix (abc.blah works fine).
Of course, it shouldn't have been coded this way to begin with but that is a different battle. I've verified that permissions are not an issue.
I'm sure others have run into this. Has anyone found a workaround other than fixing the code?
There isn't a whole lot of magic here; fix the code.
Assuming you don't have same-named objects in both schemas, you may be able to create a slew of synonyms like:
CREATE SYNONYM xyz.foo FOR dbo.foo;
...but that is going to be as much of a mess as fixing the code.

SQL Server 2005 Linked server not finding tables

I have a linked server where I can clearly see all the databases and tables, so I know the server is properly linked. However, when I try to execute a query, it says invalid object name, at the linked server's table.
The linked server is aliased as TCS, therefore, my query takes that table as
FROM [TCS].dbo.table as b
I have also tried including the database name also as FROM [TCS\db1].dbo.table.
What am I missing here?
Try including the DB name like so:
FROM [TCS].db1.dbo.table as b
I don't think you can specify the DB using a slash.
I would also check to make sure your security settings for the linked server are allowing your account to connect. This article touches on how to do that.
either:
the user (used for the link) doesn't have access to the table; Grant access;
the default DB on the server doesn't have the table. You have to change it to the relevant one or included in the db in the name: [TCS].DATABASE.dbo.table as b;

How do i get the names of all the tables inside a database?

EDIT2: Found a fix! I used the number of the desired schema instead of the name. Should've thought of that before, really! And i think the error messages could've been a bit better aswell. Thanks for all your time!
How can i get the names of all tables inside a database through sql inside asp classic?
The server is running windows 2008, iis7.5 and microsoft jet. I've tried all the querys i could find on the internet (and here) but none have worked.
If i add a ; to the query to run a set of querys at the same time it gives me an error because the statement isn't over at the semicolon.
The master.mdf database cannot be accessed because it's of unknown format.
The sysobjects variable apparently doesn't exist.
I am using mssql 2000 format. (.mdf)
The connection is made through classic asp with the Microsoft.Jet.OLEDB.4.0 provider and ADODB connection/recordset.
How do I get list of all tables in a database using TSQL?
Query to get the names of all tables in SQL Server 2008 Database
EDIT:
I've found two folders containing databases. One is in C:\program files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\mssql\binn\templates and contains master.mdf, mastlog.ldf, model.mdf, modellog.ldf, msdbdata.mdf and msdblog.ldf. The other one is also in the \binn\template data directory and contains master.mdf, mastlog.ldf, model.mdf, modellog.ldf, MSDBData.mdf, MSDBLog.ldf, mssqlsystemresource.ldf, mssqlsystemresource.mdf, tempdb.mdf and templog.ldf. Maybe these is of some interest?
How can i tell if i have permission? Does it give a permission denied error?
Please help! No, don't. Read the 2nd edit at the top.
USE YOUR_DATABASE
GO
SELECT *
FROM sys.Tables
GO
Have you tried the example from:
http://www.kamath.com/codelibrary/cl002_listtables.asp
I almost always use the INFORMATION_SCHEMA views:
SELECT * FROM INFORMATION_SCHEMA.TABLES
If this isn't working for you, the SQL user your site is running under may not have access to the system objects. This is actually a good thing, as giving your site access to the underlying database schema can leave you vulnerable to SQL injection.
So if you do go this route, proceed with caution.
The mdf by itself is useless: you need a database engine (a.k.a. a SQL Server instance) to "run" it. As I understand the question, this is your problem.
Then you can use sysobjects in your database: unless you have added your tables to the master database
There is no practical way to use an mdf directly: if nothing else download MSDE