>Sorry Cetin, bad writing.
>
>I send this on SQL Query Analyzer ( and on VFP SPT ).
>
>
>USE pubs
>
>exec sp_executesql N'USE master; SELECT @P1 ; SELECT DB_NAME()'
>, N'@P1 INT', 1
>
>SELECT DB_NAME()
>
>
>result:
>
>1
>
>master
>
>pubs
>
>
>It is correct, the USE database within sp_executesql is valid only
>within sp_executesql.
>
>From the first moment, it would seem that the same commando, constructed from VFP in order to replace the ?parameter,
>renders effective commando USE ( executed within sp_executesql ) in the connection , but I do not find one explanation.
>
>Fabio
Fabio,
Correcting this way I still get the expected results (same as in query analyzer - 1,master,pubs). Here is the code in VFP I tried :
lcTry = ;
"USE pubs;"+;
"exec sp_executesql N'USE master; SELECT @P1 ; SELECT DB_NAME()', N'@P1 INT', 1;"+;
"SELECT DB_NAME()"
local lnHandle
lnHandle=SQLStringConnect('DRIVER=SQL Server;SERVER=cetin\cetin;Trusted_connection=Yes')
SQLEXEC(lnHandle, lcTry)
SQLDisconnect(lnHandle)
Cetin