{"action":"created","issue":{"url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/426","labels_url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/426/labels{/name}","comments_url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/426/comments","events_url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/426/events","html_url":"https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/426","id":118405645,"number":426,"title":"Use fully qualified database name when retrieving column definitions …","user":{"login":"jippeholwerda","id":117410,"avatar_url":"https://avatars.githubusercontent.com/u/117410?v=3","gravatar_id":"","url":"https://api.github.com/users/jippeholwerda","html_url":"https://github.com/jippeholwerda","followers_url":"https://api.github.com/users/jippeholwerda/followers","following_url":"https://api.github.com/users/jippeholwerda/following{/other_user}","gists_url":"https://api.github.com/users/jippeholwerda/gists{/gist_id}","starred_url":"https://api.github.com/users/jippeholwerda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jippeholwerda/subscriptions","organizations_url":"https://api.github.com/users/jippeholwerda/orgs","repos_url":"https://api.github.com/users/jippeholwerda/repos","events_url":"https://api.github.com/users/jippeholwerda/events{/privacy}","received_events_url":"https://api.github.com/users/jippeholwerda/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/labels/4-1-stable","name":"4-1-stable","color":"d4c5f9"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-23T15:30:49Z","updated_at":"2015-11-23T21:15:28Z","closed_at":"2015-11-23T16:21:19Z","pull_request":{"url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/pulls/426","html_url":"https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/426","diff_url":"https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/426.diff","patch_url":"https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/426.patch"},"body":"…to support linked servers.\r\n\r\nWe have to retrieve data from SQL Server 2008. Since that doesn't work with the latest activerecord-sqlserver-adapter and we do have the possibility of using a SQL Server 2012 instance, we've configured the 2012 database engine to be able to execute queries/commands against the 2008 instance. This can be achieved by adding the 2008 server as a [\"linked server\"](https://msdn.microsoft.com/en-us/library/ms188279(v=sql.110).aspx) in the 2012 instance.\r\n\r\nHowever, querying a linked server requires using the fully qualified database name:\r\n```\r\nselect * from [server].[database].[dbo].[table]\r\n```\r\n\r\nIn the current master, using a linked server fails with the following error:\r\n```TinyTds::Error: Invalid object name 'database.INFORMATION_SCHEMA.COLUMNS'```\r\nwhen retrieving the table definition of a linked server.\r\n\r\nThis pull request should fix that by using the fully qualified database name.\r\n\r\nAn example of a model that uses a linked server is:\r\n```\r\nclass LinkedServerTest < ActiveRecord::Base\r\n  self.table_name = \"[server].table.dbo.linked_server_test\"\r\n  \r\n  # Setting the table alias used in Arel is necessary since otherwise the\r\n  # fully qualified table name is used in the select_list of the select clause,\r\n  # causing SQL Server to complain about the maximum number of prefixes.\r\n  self.arel_table.table_alias = \"linked_server_test\"\r\nend\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/comments/159066142","html_url":"https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/426#issuecomment-159066142","issue_url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/426","id":159066142,"user":{"login":"theangryangel","id":309967,"avatar_url":"https://avatars.githubusercontent.com/u/309967?v=3","gravatar_id":"","url":"https://api.github.com/users/theangryangel","html_url":"https://github.com/theangryangel","followers_url":"https://api.github.com/users/theangryangel/followers","following_url":"https://api.github.com/users/theangryangel/following{/other_user}","gists_url":"https://api.github.com/users/theangryangel/gists{/gist_id}","starred_url":"https://api.github.com/users/theangryangel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theangryangel/subscriptions","organizations_url":"https://api.github.com/users/theangryangel/orgs","repos_url":"https://api.github.com/users/theangryangel/repos","events_url":"https://api.github.com/users/theangryangel/events{/privacy}","received_events_url":"https://api.github.com/users/theangryangel/received_events","type":"User","site_admin":false},"created_at":"2015-11-23T21:15:28Z","updated_at":"2015-11-23T21:15:28Z","body":"Sorry for intruding, but I've got a question for @jippeholwerda - I had assumed that linked servers were passed SQL verbatim. Unfortunately I'm not in a position where I can test this until the end of the week and I'm dying to know the answer :sweat_smile: Are you saying that with a small 2012 (or newer instance) with a linked 2008 R2 server, I can issue FETCH and OFFSET queries (for example), and they're appropriately translated for 2008 R2?"}}