Como usar o OPENROWSET

A função OPENROWSET do T-SQL pode ser muito útil quando precisamos acessar uma informação de uma outra base de dados. Apesar do usuário DBO não ter permissão de executar a stored procedure sp_addlinkedserver, é possível informar as configurações de acesso na própria função OPENROWSET.

 A sintaxe da função é assim:  OPENROWSET ( 'provider_name'  , { 'datasource' ; 'user_id' ; 'password'   | 'provider_string' }  , { [ catalog. ] [ schema. ] object  | 'query' }   )  

No exemplo abaixo, retornamos o resultado de uma consulta feita em outra base de dados MS SQL:

 SELECT a.coluna1, a.coluna2   FROM OPENROWSET('SQLOLEDB','SERVIDOR';'LOGIN';'SENHA',   'SELECT coluna1, coluna2 FROM tabela') AS a   

Veja mais informações sobre este recurso, no Books On Line do MS SQL:
http://msdn.microsoft.com/en-us/library/ms190312%28SQL.90%29.aspx

Obs 1: Não é possível acessar um banco de dados MS Access com esta função em um servidor compartilhado, pois os clientes não tem acesso para hospedar o arquivo MDB neste mesmo servidor. Isso poderá ser feito apenas em um servidor MS SQL dedicado.

Obs 2: Acesso a servidores externos à rede da Locaweb pode gerar sobrecarga nos servidores. Caso alguma sobrecarga proveniente deste acesso venha a prejudicar o desempenho do servidor e conseqüentemente o desempenho do site de outros clientes no mesmo servidor compartilhado, desativaremos temporariamente a base de dados e entraremos em contato.

Veja também


O artigo ajudou ?
SimNão

37 Comments

I’ve just finished reading your latest blog post, and I must say, it’s outstanding! The depth of your analysis coupled with your engaging writing style made for an exceptional read. What struck me most was your ability to break down complex ideas into digestible, relatable content. Your examples and real-life applications brought the topic to life. I’ve gained a lot from your insights and am grateful for the learning. Keep up the fantastic work – your blog is a treasure trove of knowledge!

Unquestionably believe that which you said. Your favorite reason seemed to be on the web the easiest thing to be aware of. I say to you, I certainly get irked while people consider worries that they just don’t know about. You managed to hit the nail upon the top and also defined out the whole thing without having side-effects , people could take a signal. Will likely be back to get more. Thanks

Wonderful work! This is the type of info that should be shared around the internet. Shame on the search engines for not positioning this post higher! Come on over and visit my site . Thanks =)

Hi! This is kind of off topic but I need some help from an established blog. Is it very hard to set up your own blog? I’m not very techincal but I can figure things out pretty quick. I’m thinking about creating my own but I’m not sure where to begin. Do you have any points or suggestions? With thanks

Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something. I think that you could do with some pics to drive the message home a bit, but other than that, this is magnificent blog. A great read. I will definitely be back.

There are actually a lot of details like that to take into consideration. That could be a nice level to bring up. I offer the thoughts above as general inspiration however clearly there are questions like the one you carry up where crucial factor will likely be working in sincere good faith. I don?t know if greatest practices have emerged round issues like that, but I’m certain that your job is clearly recognized as a fair game. Each boys and girls really feel the impact of only a moment’s pleasure, for the remainder of their lives.

Deixe uma resposta