programming4us
programming4us
DATABASE

SQL Server 2008 : Working with Multiple-Source Queries - OpenQuery, OpenRowSet, and OpenDataSource Explained

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
Apart from using four dotted notations, you have three functions to access remote servers. Those functions are OpenQuery, OpenRowSet, and OpenDataSource. OpenDataSource and OpenRowSet commands are by default disabled, and you need to enable these options.

New & Noteworthy...: Enabling OpenDataSource and OpenRowSet Functions

As in SQL Server 2008, OpenDataSource and OpenRowSet are disabled in SQL Server 2005 by default. If you want to use these functions, you have to enable them.

In SQL Server 2005, there is a dedicated tool called SQL Server Surface Area Configuration. However, you will not find this tool with the SQL Server 2008 installation. Instead, there is a feature called Facets to enable OpenDataSource and OpenRowSet functions.


By following the steps in Exercise 1, you can enable these functions.

Exercise 1. Enabling Ad Hoc Remote Queries
  1. Start SQL Server Management Studio from Program Files | SQL Server 2008.

  2. Select Database Engine as Database Type and the SQL Server Database instance name and provide the necessary user credentials to log in to SQL Server. If you supply the correct information, you will be taken to SQL Server Management Studio.

  3. Right-click the server and select Facets from the context menu.

  4. Select Surface Area Configuration Server from the Facet drop down. As per the RTM version of SQL Server 2008, it is the last facet in the drop down.

  5. Enable AdhocRemoteQueriesEnabled as shown in Figure 1.

Figure 1. Enable Adhoc Remote Queries from Facets

OpenDataSource

Using the OpenDataSource function is the same as using a four-part name to access a Linked Server, except the OpenDataSource() function defines the link within the function instead of referencing a predefined linked server. While defining the link in code bypasses the linked server requirement, if the link location changes, then the change will affect every query that uses OpenDataSource(). In addition, OpenDataSource() will not accept variables as parameters.

SELECT Name FROM
OpenDataSource ('SQLOLEDB',Data Source ='Dinesh-Mob';User ID = sa;Password =sa')
.Family.dbo.Person


OpenQuery

For pass-through queries, the OpenQuery() function leverages a Linked Server. So it’s the easiest to develop. It also handles changes in server configuration with changing code.

SELECT * FROM OPENQUERY(
LinkedServerName,'SELECT * FROM Tour WHERE Country=''Sri Lanka''')

You can do updates as well.

UPDATE OPENQUERY(LinkedServerName,
'SELECT * FROM Tour WHERE Country=''Sri Lanka''')
SET Start ='Colombo'

OpenRowSet

The OpenRowSet function is the counterpart to the OpenDataSet( ) function. Both require the remote data source to be fully specified in the distributed query.

SELECT Name
FROM OPENROWSET('SQLOLEDB',Data Source ='Dinesh-Mob';User ID =
sa;Password =sa',
SELECT * FROM Customers Where Cust = 1')

Warning

There are several places where you can configure Link Servers. They are Facet, Provider Options, and Link Server properties. These configurations are different, and you need to make sure at which place you can do what configuration.

Other  
 
Top 10
Free Mobile And Desktop Apps For Accessing Restricted Websites
MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
TOYOTA CAMRY 2; 2.5 : Camry now more comely
KIA SORENTO 2.2CRDi : Fuel-sipping slugger
How To Setup, Password Protect & Encrypt Wireless Internet Connection
Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
Backup & Restore Game Progress From Any Game With SaveGameProgress
Generate A Facebook Timeline Cover Using A Free App
New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
- Messages forwarded by Outlook rule go nowhere
- Create and Deploy Windows 7 Image
- How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
- Creating and using an unencrypted cookie in ASP.NET
- Directories
- Poor Performance on Sharepoint 2010 Server
- SBS 2008 ~ The e-mail alias already exists...
- Public to Private IP - DNS Changes
- Send Email from Winform application
- How to create a .mdb file from ms sql server database.......
programming4us programming4us
programming4us
 
 
programming4us