1

I am using a SQL database residing on my local computer. I want to access a table from a database residing on another computer using SQL query.

I have been able to connect the remote database with my database and all its tables are shown in Enterprise manager on my local machine. I have added remote SQL Server in my local SQL Server.

When I use select statement in my local SQL server it gives the message database does not exist or access denied.

Any help in this would highly be appreciated.

EDITED

Select * from [ServerName].DatabaseName.dbo.tableName
12
  • 1
    check you connection string Commented Oct 8, 2016 at 6:41
  • 1
    Can you show us the code you are using? Commented Oct 8, 2016 at 6:42
  • 1
    from where you are running the Select query? Commented Oct 8, 2016 at 6:48
  • 1
    Can you post the select query? Commented Oct 8, 2016 at 6:55
  • 2
    You need to create a linked server, but its generally not the best idea. What are you trying to do? sqlserverplanet.com/dba/how-to-add-a-linked-server Commented Oct 8, 2016 at 7:07

1 Answer 1

2

Use OPENROWSET
Example

    SELECT t.version FROM 
    OPENROWSET('SQLNCLI', 'server=Myserver;UID=xxxx;pwd=yyyy',
    'select @@version version') t

Note:

SQLNCLI is the name of installed OLE DB provider

Datasource: {server=Myserver;UID=xxx;pwd=yyy}

You have to enable OPENROWSET by executing the following script:

  sp_configure 'show advanced options', 1
  reconfigure

  go
  sp_configure 'Ad Hoc Distributed Queries', 1
   reconfigure 

OPENROWSET is like connecting to a linked server

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.