How to Configure, Manage, Use, and Troubleshoot Linked ...


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

How to Configure, Manage, Use, and Troubleshoot Linked ...

  1. 1. How to Configure, Manage, Use, and Troubleshoot Linked Servers With Microsoft SQL Server William P. Carroll SQL Server Support Engineer Microsoft Corporation
  2. 2. Objectives and Agenda <ul><li>Understand how Microsoft® SQL Server™ implements linked servers </li></ul><ul><li>How to set up and configure linked servers </li></ul><ul><li>Different techniques for writing linked server queries </li></ul><ul><li>How to troubleshoot common linked server issues </li></ul><ul><li>Questions and answers </li></ul>
  3. 3. Introduction and Architecture (2) <ul><li>What are linked servers? </li></ul><ul><ul><li>Link to a remote data source </li></ul></ul><ul><ul><li>The link uses an OLE DB provider </li></ul></ul><ul><ul><li>SQL Server will use the link to run commands against the OLE DB provider for the remote data source </li></ul></ul><ul><li>The functionality of the OLE DB provider will determine what commands and functions the linked server can accomplish </li></ul>
  4. 4. Introduction and Architecture (3) <ul><li>What are OLE DB providers? </li></ul><ul><ul><li>Microsoft created OLE DB </li></ul></ul><ul><ul><li>OLE DB is an open set of component object model (COM) interfaces that provide applications with consistent access to data stored in diverse sources </li></ul></ul><ul><li>All linked servers use OLE DB </li></ul><ul><li>OLE DB providers are installed with MDAC or third-party installation packages </li></ul>
  5. 5. Introduction and Architecture (4) <ul><li>ODBC versus OLE DB </li></ul><ul><li>ODBC </li></ul><ul><ul><li>Established standard for accessing relational database systems </li></ul></ul><ul><li>OLE DB </li></ul><ul><ul><li>Can access relational database systems and non-relational database systems </li></ul></ul><ul><li>MSDASQL </li></ul>
  6. 6. Introduction and Architecture (5) <ul><li>Linked servers versus remote servers </li></ul><ul><ul><li>Remote servers permit a client to connect to one instance of SQL Server and run a stored procedure on another instance of SQL Server without the client establishing another connection </li></ul></ul><ul><ul><li>Remote servers remain only for backward compatibility </li></ul></ul><ul><ul><li>Remote servers do not use OLE DB providers </li></ul></ul><ul><ul><li>Try to convert remote servers to linked servers </li></ul></ul>
  7. 7. Introduction and Architecture (6) <ul><li>SQL Server address space </li></ul>
  8. 8. Introduction and Architecture (7) <ul><li>Linked server architecture </li></ul>
  9. 9. Introduction and Architecture (8) <ul><li>OLE DB providers tested with SQL Server 2000 </li></ul><ul><ul><li>Microsoft OLE DB provider for SQL Server </li></ul></ul><ul><ul><li>Microsoft OLE DB provider for ODBC </li></ul></ul><ul><ul><li>Microsoft OLE DB provider for jet version 4.00 </li></ul></ul><ul><ul><li>Microsoft OLE DB provider for DTS packages </li></ul></ul><ul><ul><li>Microsoft OLE DB provider for Oracle version 2.6 </li></ul></ul><ul><ul><li>Microsoft OLE DB provider for Microsoft directory services </li></ul></ul><ul><ul><li>Microsoft OLE DB provider for Microsoft indexing services </li></ul></ul><ul><ul><li>Microsoft OLE DB provider for DB2 </li></ul></ul>
  10. 10. Setup and Configuration
  11. 11. Setup and Configuration (2)
  12. 12. Setup and Configuration (3)
  13. 13. Setup and Configuration (4)
  14. 14. Setup and Configuration (5)
  15. 15. Setup and Configuration (6) <ul><li>Sp_addlinkedserver </li></ul><ul><li>Sp_addlinkedsvrlogin </li></ul><ul><li>Sp_serveroption </li></ul><ul><li>Sp_dropserver </li></ul><ul><li>Sp_droplinkedsvrlogin </li></ul><ul><li>Sp_linkedservers </li></ul><ul><li>Sp_helpserver </li></ul><ul><li>xp_enum_oledb_providers </li></ul><ul><li>Select * from master..sysservers </li></ul><ul><li>HKEY_LOCAL_MACHINESoftware MicrosoftMicrosoft SQLServerProviders </li></ul>
  16. 16. Setup and Configuration (7) <ul><li>Security account delegation </li></ul><ul><li>All servers must be running Windows 2000 with Kerberos support enabled, and must be using Microsoft Active Directory® </li></ul><ul><li>Active Directory must be configured </li></ul><ul><li>Must use TCP/IP </li></ul><ul><li>The service principal name (SPN) must be assigned to the service account of the SQL Server service on that specific computer (setspn.exe) </li></ul>
  17. 17. Using Linked Servers <ul><li>Linked_server_name.Catalog.Schema.Object_name </li></ul><ul><li>Sp_tables_ex, sp_columns_ex </li></ul><ul><li>Select * from sql2.pubs.dbo.authors </li></ul><ul><li>Select * from ora2..SCOTT.DEPT </li></ul><ul><li>Select * from mdb2…customer </li></ul><ul><li>Join multiple tables, join local and remote tables </li></ul>
  18. 18. Using Linked Servers (2) <ul><li>OPENQUERY ( linked_server , ' query ' ). </li></ul><ul><li>Select * from openquery (server2, ‘select * from authors’) </li></ul><ul><li>For parameters, build openquery dynamic string, then run the string </li></ul><ul><li>If performance becomes an issue with four part name syntax, test with openquery syntax </li></ul>
  19. 19. Using Linked Servers (3) <ul><li>Insert openquery (server2, ‘select * from northwind.dbo.products’) values (78, ‘TestName’, 1, 1, ‘10 boxes’,18.000, 20, 0, 10, 0) </li></ul><ul><li>Update openquery (server2, ‘select * from northwind.dbo.products where productid = 2’) set ProductName= ‘Smith’ </li></ul><ul><li>Delete from openquery (server2, ‘select * from northwind.dbo.products where productid = 78’) </li></ul>
  20. 20. Using Linked Servers (4) <ul><li>OPENROWSET ( ' provider_name '     , { ' datasource ' ; ' user_id ' ; ' password '         | ' provider_string ' }     , { [ catalog . ] [ schema . ] object         | ' query ' }     ) </li></ul><ul><li>No linked server has to be defined </li></ul>
  21. 21. Using Linked Servers (5) <ul><li>Can run remote stored procedures for SQL Server </li></ul><ul><li>Exec server2.Master..Sp_who </li></ul><ul><li>Cannot run remote stored procedures for Oracle </li></ul>
  22. 22. Using Linked Servers (6) <ul><li>Set xact_abort on </li></ul><ul><li>Most OLE DB providers require xact_abort to be set to on for data modification statements in an implicit or explicit transaction </li></ul><ul><li>Set xact_abort on </li></ul><ul><li>begin distributed tran </li></ul><ul><li>--distributed query 1 </li></ul><ul><li>--distributed query 2 </li></ul><ul><li>commit tran </li></ul>
  23. 23. Troubleshooting <ul><li>7399 error is a generic multipurpose error from SQL Server </li></ul><ul><li>Dbcc traceon(7300, 3604) </li></ul><ul><li>Trace flag 7300 receives error information from the OLE DB provider and 3604 shows it to the client </li></ul><ul><li>Capture “OLE DB Errors” event in “Errors and Warnings” event category in SQL Profiler </li></ul>
  24. 24. Troubleshooting (2) <ul><li>Determine if the problem is with SQL Server (linked server configuration or query plan) or the OLE DB provider </li></ul><ul><li>RowsetViewer.exe </li></ul>
  25. 25. Troubleshooting (3) <ul><li>17803 Insufficient memory available </li></ul><ul><li>Run Instcat.sql on SQL Server 6.5 </li></ul><ul><li>Set Statistics profile on </li></ul><ul><li>Oracle: Q280106, Q244661 </li></ul><ul><li>DB2: Q222937, Q218590, Q287093 </li></ul>
  26. 26. Additional Resources <ul><li>Q203638, “HOWTO: Return Information About SQL Server Linked Servers” </li></ul><ul><li>Q280106, “HOWTO: Set Up and Troubleshoot a Linked Server to Oracle in SQL Server” </li></ul><ul><li>Q207595, “HOWTO: SQL Server 7.0 Distributed Query With FoxPro .dbf Files” </li></ul><ul><li>Q246255, “HOWTO: Use a SQL Server 7.0 Distributed Query w/ Linked Server” </li></ul><ul><li>Q314520, “HOW TO: Pass a Variable to a Linked Server Query” </li></ul><ul><li>Q244661, “INF: Limitations of Microsoft Oracle ODBC Driver and OLEDB Provider” </li></ul><ul><li>Q197456, “INF: Optimizing Distributed Query with Numeric Predicates” </li></ul><ul><li>Q274348, “INF: Distributed Queries Executed Within a Trigger Enlist MSDTC” </li></ul>
  27. 27. Additional Resources (2) <ul><li>Q222937, “INF: Creating a Linked Server to DB2 w/ OLE DB Provider for DB2” </li></ul><ul><li>Q218590, “INF: Configuring Data Sources for the Microsoft OLE DB Provider for DB2” </li></ul><ul><li>Q242025, “INF: How to Set Up Security for Linked Server to OLAP Services” </li></ul><ul><li>Q271669, “INF: Distributed Queries are not Run as Parallel Query Steps” </li></ul><ul><li>Q277002, “PRB: Distributed Query Against Oracle 8.x Fails” </li></ul><ul><li>Q278984, “PRB: Error 7321 Occurs When You Run a Query That Uses Four-Part Names Against DB2 on an AS/400 Computer” </li></ul><ul><li>Q270119, “PRB: 7357/7320 Error While Performing UPDATE, INSERT, or DELETE on Remote Table Using OpenQuery Via Linked Server” </li></ul>
  28. 28. Additional Resources (3) <ul><li>Q220915, “PRB: SQL Distributed Query with Oracle Needs Oracle Client and Networking Components” </li></ul><ul><li>Q286464, “PRB: Error 7008 Occurs When Using DB2OLEDB Provider with DB2/400” </li></ul><ul><li>Q200797, “PRB: OPTIMIZER LOCK HINTS Error with Open Query” </li></ul><ul><li>Q200794, “PRB: Sp_addlinkedserver Does Not Validate the OLE DB Provider” </li></ul><ul><li>Q240340, “PRB: SQL Distributed Query w/ Oracle &quot;Could not open table&quot; Error” </li></ul><ul><li>Q306649, “PRB: Error When You Implement Nested Transaction with OLE DB Provider for SQL Provider” </li></ul><ul><li>Q238477, “PRB: Message 18456 from a Distributed Query” </li></ul><ul><li>Q230576, “PRB: Dist. Query Involving External Provider Not Supported When Using Windows NT Authentication” </li></ul>
  29. 29. Additional Resources (4) <ul><li>Q221552, “PRB: SQL Distributed Query with Oracle NUMERIC Column Gives Error” </li></ul><ul><li>Q296685, “FIX: Cannot Execute SELECT COUNT(*) Against DB2 on Mainframe Using Four-Part Name” </li></ul><ul><li>Q281185, “FIX: Linked Index Server Query Through OLE DB Provider with OR Clause Reports Error 7349” </li></ul><ul><li>Q293758, “FIX: Nullability Changes Not Handled by SQL Server with Linked Server Queries to DB2” </li></ul><ul><li>Q306401, “FIX: Error Message 7355 &quot;..Inconsistent metadata for a column&quot; Occurs When You Use a Linked Server” </li></ul><ul><li>Q265865, “FIX: Float Data Inaccurately Converted When Sent to Linked Server” </li></ul>
  30. 30. Questions and Answers
  31. 31. <ul><li>Thank you for joining today’s Microsoft Support </li></ul><ul><li>WebCast. </li></ul><ul><li>For information about all upcoming Support WebCasts, </li></ul><ul><li>and access to the archived content (streaming media </li></ul><ul><li>files, PowerPoint ® slides, and transcripts), visit: </li></ul><ul><li>http:// / </li></ul><ul><li>Your feedback is sincerely appreciated. Please send any </li></ul><ul><li>comments or suggestions about the Support </li></ul><ul><li>WebCasts to [email_address] . </li></ul>