0

I implement and support a software applicatoin that allows me to create macros within the application. One of the macro steps is to execute a SQL procedure. When I attempt to run a macro that is executing a stored proc (_TSi_CustomerAccountCorrection) I'm seeing this error:

Error 0 executing [__TSi__CustomerAccountCorrection].
Invalid object name 'TSI_ProService.dbo.Customer'.

If I run this stored proc in SQL Query Analyzer (SQL 2000 using Integrated Security), the proc runs just fine. The application I'm running it through uses a SQL connection string that is set to use integrated security and I'm logged on as the same exact user as well.

Unfortunately, I do not have the source code for the application. I was hoping that someone might recognize what is going on here or at least give me a suggestion as to what the issue might be.

As far as I can see, when running the stored proc through the application and through the query analyzer is exactly the same.

Here is the stored proc:

CREATE  PROCEDURE [dbo].[__TSi__CustomerAccountCorrection] AS
set xact_abort on
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ 
BEGIN TRANSACTION trans1
DECLARE cur_cust CURSOR FOR
 SELECT [AccountNumber] FROM DBSTR1.HQ.dbo.PSD_CustomerExport
DECLARE @accountNumber varchar(50);
DECLARE @custAccountNumber varchar(50);
DECLARE @query varchar(500);
OPEN cur_cust;

FETCH NEXT FROM cur_cust INTO @accountNumber;

WHILE @@FETCH_STATUS = 0 BEGIN
 set @custAccountNumber = (SELECT TOP 1 [Account] FROM [Customer] WHERE [UserData2] = @accountNumber)

 if @custAccountNumber is null
 begin
  SET @custAccountNumber = @accountNumber
 end

 --UPDATE DBSTR1.HQ.dbo.PSD_CustomerExport SET [VcrAccountNumber] = @custAccountNumber WHERE [AccountNumber] = @accountNumber
 UPDATE DBSTR1.HQ.dbo.PSD_CustomerExport SET [VcrAccountNumber] = @custAccountNumber WHERE CURRENT OF cur_cust

 FETCH NEXT FROM cur_cust INTO @accountNumber;
END
CLOSE cur_cust;
DEALLOCATE cur_cust;
COMMIT TRANSACTION trans1
GO

Any suggestions?

1
  • 1
    You sure it's running on the same user ? Feels like a default sql schema error. Commented Aug 8, 2011 at 20:22

1 Answer 1

1

It's not executing in the same DB context when you run it remotely vs. when you run it in SSMS.

Notice that the customer table is not using the three part name. SQL Server is making assumptions about the Database and schema that the customer table is in and is guessing wrong.

It is using whatever the default context is for the connection, which from your error code is likely the database TSI_ProService and the schema defaults to dbo. One or both of these are incorrect for that table.

What DB and schema are that table in? Use the 3PN (Database.schema.object) in the call in the proc and I think it will probably work fine.

Sign up to request clarification or add additional context in comments.

5 Comments

What I don't understand is that the table is TSIPro_Service.dbo.Customer... By the way I typed the error incorrectly the error was TSIPro_Service not "TSI_ProService"
@user - It doesn't matter what DB it's in if that DB is not the default for the connection you are initializing for the remote call.
I'm a little slow... so are you telling me that I should replace "Customer" with "TSIPro_Service.dbo.Customer"?
Yes. It's generally ALWAYS a good idea in procedures/views/scripts to fully qualify you object names unless you have a good reason NOT to.
Oh ok... thanks for the advice and the tip! Unfortunately, I do not have my customers laptop right now so I cannot check this until later and I can try it out... I'll let you know and thanks again for everything!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.