9 Eylül 2012 Pazar

Sql'de Linked Server Olmadan Uzaktaki Sunucuya Bağlantı


Bildiğiniz gibi LinkedServer tanımlayarak A server’ı üzerinden B Server’ında select,update gibi işlemleri yapabilmemiz mümkün.
Bugün anlatacağım OpenDataSource komutu ile linked server’a gerek kalmadan bu işlemleri nasıl yapabileceğimizi görüyor olacağız.
OpenDataSource kullanılabilmesi için sorguyu çalıştıran server’da Ad Hoc Distributed Queriesözelliğinin enable edilmesi gerekmektedir.
Aksi halde şöyle bir hata alınır.
Msg 15281, Level 16, State 1, Line 1 
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.
Ad Hoc Distributed Queries özelliğini aktif etmek için sorguyu çalıştıran server’da şu script’i çalıştırabilirsiniz.
1exec sp_configure 'show advanced options',1
2ReConfigure with override
3exec sp_configure 'Ad Hoc Distributed Queries',1
4ReConfigure with override
5exec sp_configure 'show advanced options',0
6ReConfigure with override
Şimdi kullanıma bakalım.
1SELECT top 10 * FROM OPENDATASOURCE( 'SQLOLEDB', 
2'Data Source=Server2\sql2008;User ID=LoginName;Password=Password').ADRES.dbo.IL 





1 yorum:

  1. SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure

    hatası alınırsa aşağıdaki kodu çalıştırınız..


    sp_configure 'show advanced options', 1
    RECONFIGURE
    GO
    sp_configure 'ad hoc distributed queries', 1
    RECONFIGURE
    GO

    YanıtlaSil