|
-
Jul 10th, 2006, 03:22 PM
#1
Thread Starter
Lively Member
QUERY on two different servers
If I have two SQL Server connections open to two different servers...can I run a query, for instance a INNER JOIN on tables on seperate servers?
-
Jul 10th, 2006, 03:51 PM
#2
Re: QUERY on two different servers
YEs.... and no.... or rather no and yes.
You can, but the user context that is running the query will have to have acces to both eservers.
If I remember right.... hte syntax is:
Server.Database.dbo.TableName
-tg
-
Jul 10th, 2006, 04:11 PM
#3
Thread Starter
Lively Member
Re: QUERY on two different servers
Apprently I need to do linked servers to do this?
-
Jul 10th, 2006, 09:50 PM
#4
Re: QUERY on two different servers
I don't know for 100% sure.... but any time I've needed to do it, it has been through linked server connection, so I assume that one does.
-tg
-
Jul 11th, 2006, 07:41 AM
#5
Re: QUERY on two different servers
We have also always used LINKED SERVERS - even to go to obscure places like PERVASIVE...
-
Jul 11th, 2006, 08:00 AM
#6
Re: QUERY on two different servers
Another way of doing this would be to use OPENDATASOURCE function. You should be able to check Books Online for a sample.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jul 11th, 2006, 08:01 AM
#7
Re: QUERY on two different servers
I believe I used OPENDATASOURCE for that PERVASIVE DB but still needed the DSN connection string to be loaded as a LINKED SERVER - I will check when I get into work later...
-
Jul 11th, 2006, 08:07 AM
#8
Thread Starter
Lively Member
Re: QUERY on two different servers
That would be awesome if yall could check on this for me.
-
Jul 11th, 2006, 08:12 AM
#9
Re: QUERY on two different servers
 Originally Posted by mlosso
That would be awesome if yall could check on this for me.
A simple example would be
PHP Code:
SELECT *
FROM OPENDATASOURCE(
'SQLOLEDB',
'Data Source=ServerName;User ID=MyUID;Password=MyPass'
).Northwind.dbo.Categories
As taken from BOL.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jul 11th, 2006, 08:28 AM
#10
Thread Starter
Lively Member
Re: QUERY on two different servers
Ya I saw that on MSDN. Working with it now, can't seem to get it work just right yet.
-
Jul 11th, 2006, 08:34 AM
#11
Thread Starter
Lively Member
Re: QUERY on two different servers
Is it possible that OPENDATASOURCE CAN BE BLOCKED?
-
Jul 11th, 2006, 08:42 AM
#12
Re: QUERY on two different servers
I don't know of whether it can be blocked. I don't think so. If you are using Right userId and Password then you should be able to use it properly.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jul 11th, 2006, 08:51 AM
#13
Re: QUERY on two different servers
Have you tried LINKED SERVER yet?
Go into ENTERPRISE MANAGER - under the SECURITY branch in the object panel on the left side open LINKED SERVERS - you can right-click on that to add a NEW LINKED SERVER.
Fill in the various text boxes - security and what not - and that server will appear available to you.
For example - we linked to a SERVER called STRATACS - then in a QUERY in our regular local database/table we were able to:
SELECT * FROM STRATACS.TVBD.DBO.PARTYLOG.
Using LINKED SERVERS allows you to access tables with standard SELECTS and JOINS - that's a very nice benefit over OPENDATASOURCE.
For our PERVASIVE DB that we did use OPENQUERY with we also LINKED servers. Since it was not SQL SERVER we selected OTHER DATA SOURCE and chose OLEDB PROVIDER FOR ODBC as the PROVIDER NAME.
Then in STORED PROCEDURES we could:
SELECT * FROM OPENQUERY(LINKNAME, 'SELECT...')
This executes the 'SELECT ...' on the ODBC connection to that PERVASIVE DB.
-
Jul 11th, 2006, 08:52 AM
#14
Thread Starter
Lively Member
Re: QUERY on two different servers
Reason I have not done Linked Server is because I must request access to do it, which could take some time. I need to do the OPENDATASOURCE using Windows Authentication...doesnt seem to be working..
-
Jul 11th, 2006, 08:54 AM
#15
Re: QUERY on two different servers
Should be a matter of specifying INTEGRATED SECURITY instead of that USERNAME or PASSWORD...
-
Jul 11th, 2006, 09:24 AM
#16
Thread Starter
Lively Member
Re: QUERY on two different servers
Thats what I thought, but when I do specify SSPI, it says server cannot be found when I clearly am connected to it in Enterprise Manager...any special lashes or backslashes?
-
Jul 11th, 2006, 09:34 AM
#17
Re: QUERY on two different servers
This works:
Code:
Select *
From OpenDataSource('SQLOLEDB'
,'DATASOURCE=servername;INTEGRATED SECURITY=SSPI').dbname.dbo.tablename
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|