Lazy Schema Validation


i have scenario need create sp in db1 references table in db2 before db2 created. db2 referenced via linked server, not have recreate if/when moves server. seems lazy schema validation allow me create proc without checking linked server validation.
unfortunately, not work. @ least tell me why it's not working? , perhaps tell me need make work?


i following error when try create sp
msg 7314, level 16, state 1, procedure testproc, line 4
the ole db provider "sqlncli" linked server "lnkdb2" not contain table ""testdb"."dbo"."testtable"".  table either not exist or current user not have permissions on table.

 

 

 

sample code:

 

use master
go

if exists(select * sysservers srvname = 'lnkdb2')
                        exec sp_dropserver 'lnkdb2', n'droplogins'

exec sp_addlinkedserver
          @server       = 'lnkdb2'
        , @srvproduct   = ''
        , @provider='sqloledb'
        , @datasrc= @@servername

exec sp_serveroption 
        'lnkdb2', 'data access', 'true'

exec sp_serveroption 
        'lnkdb2', 'lazy schema validation', 'true'
go

--****************************************
use testdb
go

if  exists (select * sys.objects object_id = object_id(n'dbo.testproc') )
        drop procedure dbo.testproc
go

create procedure dbo.testproc
as
        select  t.key_string
        lnkdb2.db2.dbo.testtable t

go

it's little unclear me .... db2 database exist already?  if so, table testtable in database not there yet?

 

if answer "yes" both of these, implying know structure of table before created.  so, i'd offer 2 workarounds.  first, create empty table in other database schema validates.  second, create empty table in current database same structure , modify stored proc when table available on linked server.

 

regarding why getting validation, books online seems little contradicatory in it's explainations of option.  1 entry in bol indicates validation occur when lazy schema validation set either "true" or "false".  the property controls when takes place. 

 

so, don't think i've answered question of "why?" have acceptable workaround. 

 

b.



SQL Server  >  SQL Server Database Engine



Comments

Popular posts from this blog

Motherboard replacement

Cannot create Full Text Search catalog after upgrading to V12 - Database is not fully started up or it is not in an ONLINE state

Remote Desktop App - Error 0x207 or 0x607