Avatar billede tonyhtp Nybegynder
18. april 2002 - 10:17 Der er 5 kommentarer

Accessing linked server through Stored Procedures

I'm trying to execute the following statement in a stored procedure:

-------------------------------------------

DECLARE @MyId int

DECLARE Monjacursor cursor for
    SELECT PersonId
    FROM ProntoRemote.pronto.dbo.person
    WHERE NOT PersonId IN (SELECT DISTINCT PersonId FROM attendance)for read only

OPEN Monjacursor

FETCH NEXT FROM Monjacursor INTO @MyId

WHILE @@FETCH_STATUS = 0
  BEGIN
    INSERT INTO Attendance(PersonId,UpdateDate,CreateDate)
    VALUES(@MyId,GetDate(),GetDate())
   
    FETCH NEXT FROM Monjacursor INTO @MyId
  END

CLOSE Monjacursor
DEALLOCATE Monjacursor

--------------------------------------

It works fine in Query Analyzer but I get the following errormessage when i try to save the stored procedure.

"Error 7405: Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these option and then reissue your query."

I tried to set the ANSI_NULL and ANSI_WARNINGS to ON in the stored procedure but this did not help.

Any suggestions???
Avatar billede terry Ekspert
18. april 2002 - 11:03 #1
I cant really see any problems. The ERROR does mention the connection and I can see that your selecting from another server/dB so it may have something to do with that!

Are you saying that you can actually RUN the SP in Query Analyzer, you are not just checking the syntax?

Another thing! Why dont you just make a INSERT INTO .... Select instead of looping? This may simplify things some!
Avatar billede tonyhtp Nybegynder
18. april 2002 - 11:24 #2
True, thanks.

No, I can't save the SP, but I can run the same code in Query Analyzer (it executes, so the connection works fine).

The problem still consists, I can't save the SP...
Avatar billede terry Ekspert
18. april 2002 - 11:37 #3
In Query Analyzer you can choose which dB you are in try changing it to the OTHER dB and see what happens!
Avatar billede tonyhtp Nybegynder
18. april 2002 - 11:43 #4
By 'OTHER', do you mean the remote, linked server?
The remote server is not accesible through QA since it is a 'virtual' server. However, I can view it's tables through EM.

Thanks for taking your time.  :)
Avatar billede terry Ekspert
18. april 2002 - 12:23 #5
Yes I did mean the linked server, but as you say it isnt in the list.

Dont know what to suggest then :o(
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester