Upload
tess98
View
809
Download
35
Embed Size (px)
Citation preview
How to Configure, Manage, How to Configure, Manage, Use, and Troubleshoot Use, and Troubleshoot Linked Servers With Linked Servers With Microsoft SQL ServerMicrosoft SQL Server
William P. CarrollWilliam P. CarrollSQL Server Support EngineerSQL Server Support EngineerMicrosoft CorporationMicrosoft Corporation
2
Objectives and AgendaObjectives and Agenda
Understand how Microsoft® SQL Server™ Understand how Microsoft® SQL Server™ implements linked serversimplements linked servers
How to set up and configure linked serversHow to set up and configure linked servers Different techniques for writing linked server Different techniques for writing linked server
queriesqueries How to troubleshoot common linked server How to troubleshoot common linked server
issuesissues Questions and answersQuestions and answers
3
Introduction and Architecture Introduction and Architecture (2)(2)
What are linked servers?What are linked servers? Link to a remote data sourceLink to a remote data source The link uses an OLE DB providerThe link uses an OLE DB provider SQL Server will use the link to run commands SQL Server will use the link to run commands
against the OLE DB provider for the remote data against the OLE DB provider for the remote data sourcesource
The functionality of the OLE DB provider will The functionality of the OLE DB provider will determine what commands and functions determine what commands and functions the linked server can accomplishthe linked server can accomplish
4
Introduction and Architecture Introduction and Architecture (3)(3)
What are OLE DB providers?What are OLE DB providers? Microsoft created OLE DBMicrosoft created OLE DB OLE DB is an open set of component object OLE DB is an open set of component object
model (COM) interfaces that provide applications model (COM) interfaces that provide applications with consistent access to data stored in diverse with consistent access to data stored in diverse sourcessources
All linked servers use OLE DBAll linked servers use OLE DB OLE DB providers are installed with MDAC or OLE DB providers are installed with MDAC or
third-party installation packagesthird-party installation packages
5
Introduction and Architecture Introduction and Architecture (4)(4)
ODBC versus OLE DBODBC versus OLE DB ODBCODBC
Established standard for accessing relational Established standard for accessing relational database systemsdatabase systems
OLE DBOLE DB Can access relational database systems and non-Can access relational database systems and non-
relational database systemsrelational database systems
MSDASQLMSDASQL
6
Introduction and Architecture Introduction and Architecture (5)(5)
Linked servers versus remote serversLinked servers versus remote servers Remote servers permit a client to connect to one Remote servers permit a client to connect to one
instance of SQL Server and run a stored instance of SQL Server and run a stored procedure on another instance of SQL Server procedure on another instance of SQL Server without the client establishing another connectionwithout the client establishing another connection
Remote servers remain only for backward Remote servers remain only for backward compatibilitycompatibility
Remote servers do not use OLE DB providersRemote servers do not use OLE DB providers Try to convert remote servers to linked serversTry to convert remote servers to linked servers
7
Introduction and Architecture Introduction and Architecture (6)(6)
SQL Server address spaceSQL Server address space
8
Introduction and Architecture Introduction and Architecture (7)(7)
Linked server architectureLinked server architecture
9
Introduction and Architecture Introduction and Architecture (8)(8)
OLE DB providers tested with SQL Server OLE DB providers tested with SQL Server 20002000 Microsoft OLE DB provider for SQL ServerMicrosoft OLE DB provider for SQL Server Microsoft OLE DB provider for ODBCMicrosoft OLE DB provider for ODBC Microsoft OLE DB provider for jet version 4.00Microsoft OLE DB provider for jet version 4.00 Microsoft OLE DB provider for DTS packagesMicrosoft OLE DB provider for DTS packages Microsoft OLE DB provider for Oracle version 2.6Microsoft OLE DB provider for Oracle version 2.6 Microsoft OLE DB provider for Microsoft directory Microsoft OLE DB provider for Microsoft directory
servicesservices Microsoft OLE DB provider for Microsoft indexing Microsoft OLE DB provider for Microsoft indexing
servicesservices Microsoft OLE DB provider for DB2Microsoft OLE DB provider for DB2
10
Setup and ConfigurationSetup and Configuration
11
Setup and Configuration Setup and Configuration (2)(2)
12
Setup and Configuration Setup and Configuration (3)(3)
13
Setup and Configuration Setup and Configuration (4)(4)
14
Setup and Configuration Setup and Configuration (5)(5)
15
Setup and Configuration Setup and Configuration (6)(6)
Sp_addlinkedserverSp_addlinkedserver Sp_addlinkedsvrloginSp_addlinkedsvrlogin Sp_serveroptionSp_serveroption Sp_dropserverSp_dropserver Sp_droplinkedsvrloginSp_droplinkedsvrlogin Sp_linkedserversSp_linkedservers Sp_helpserverSp_helpserver xp_enum_oledb_providersxp_enum_oledb_providers Select * from master..sysserversSelect * from master..sysservers HKEY_LOCAL_MACHINE\Software\HKEY_LOCAL_MACHINE\Software\
Microsoft\Microsoft SQLServer\ProvidersMicrosoft\Microsoft SQLServer\Providers
16
Setup and Configuration Setup and Configuration (7)(7)
Security account delegationSecurity account delegation All servers must be running Windows 2000 All servers must be running Windows 2000
with Kerberos support enabled, and must be with Kerberos support enabled, and must be using Microsoft Active Directory®using Microsoft Active Directory®
Active Directory must be configuredActive Directory must be configured Must use TCP/IPMust use TCP/IP The service principal name (SPN) must be The service principal name (SPN) must be
assigned to the service assigned to the service accountaccount of the SQL of the SQL Server service on that specific computerServer service on that specific computer(setspn.exe)(setspn.exe)
17
Using Linked ServersUsing Linked Servers
Linked_server_name.Catalog.Schema.ObjectLinked_server_name.Catalog.Schema.Object_name_name
Sp_tables_ex, sp_columns_exSp_tables_ex, sp_columns_ex Select * from sql2.pubs.dbo.authorsSelect * from sql2.pubs.dbo.authors Select * from ora2..SCOTT.DEPT Select * from ora2..SCOTT.DEPT Select * from mdb2…customerSelect * from mdb2…customer Join multiple tables, join local and remote Join multiple tables, join local and remote
tablestables
18
Using Linked Servers Using Linked Servers (2)(2)
OPENQUERYOPENQUERY ( ( linked_server linked_server , ', 'queryquery' ).' ). Select * from openquery (server2, ‘select * Select * from openquery (server2, ‘select *
from authors’)from authors’) For parameters, build openquery dynamic For parameters, build openquery dynamic
string, then run the stringstring, then run the string If performance becomes an issue with four If performance becomes an issue with four
part name syntax, test with openquery syntaxpart name syntax, test with openquery syntax
19
Using Linked Servers Using Linked Servers (3)(3)
Insert openquery (server2, ‘select * from Insert openquery (server2, ‘select * from northwind.dbo.products’) values (78, northwind.dbo.products’) values (78, ‘TestName’, 1, 1, ‘10 boxes’,18.000, 20, 0, 10, ‘TestName’, 1, 1, ‘10 boxes’,18.000, 20, 0, 10, 0) 0)
Update openquery (server2, ‘select * from Update openquery (server2, ‘select * from northwind.dbo.products where productid = northwind.dbo.products where productid = 2’) set ProductName= ‘Smith’2’) set ProductName= ‘Smith’
Delete from openquery (server2, ‘select * Delete from openquery (server2, ‘select * from northwind.dbo.products where from northwind.dbo.products where productid = 78’)productid = 78’)
20
Using Linked Servers Using Linked Servers (4)(4)
OPENROWSETOPENROWSET ( ' ( 'provider_nameprovider_name' ' , { ' , { 'datasourcedatasource' ; '' ; 'user_iduser_id' ; '' ; 'passwordpassword' ' | ' | 'provider_stringprovider_string' } ' } , { [ , { [ catalogcatalog. ] [ . ] [ schemaschema. ] . ] objectobject | ' | 'queryquery' } ' } ) )
No linked server has to be definedNo linked server has to be defined
21
Using Linked Servers Using Linked Servers (5)(5)
Can run remote stored procedures for SQL Can run remote stored procedures for SQL ServerServer
Exec server2.Master..Sp_whoExec server2.Master..Sp_who Cannot run remote stored procedures for Cannot run remote stored procedures for
OracleOracle
22
Using Linked Servers Using Linked Servers (6)(6)
Set xact_abort onSet xact_abort on Most OLE DB providers require Most OLE DB providers require
xact_abort to be set to on for data xact_abort to be set to on for data modification statements in an implicit or modification statements in an implicit or explicit transactionexplicit transaction
Set xact_abort onSet xact_abort on
begin distributed tranbegin distributed tran
--distributed query 1--distributed query 1
--distributed query 2--distributed query 2
commit trancommit tran
23
TroubleshootingTroubleshooting
7399 error is a generic multipurpose error 7399 error is a generic multipurpose error from SQL Serverfrom SQL Server
Dbcc traceon(7300, 3604)Dbcc traceon(7300, 3604) Trace flag 7300 receives error information Trace flag 7300 receives error information
from the OLE DB provider and 3604 shows from the OLE DB provider and 3604 shows it to the clientit to the client
Capture “OLE DB Errors” event in “Errors Capture “OLE DB Errors” event in “Errors and Warnings” event category in SQL and Warnings” event category in SQL ProfilerProfiler
24
Troubleshooting Troubleshooting (2)(2)
Determine if the problem is with SQL Server Determine if the problem is with SQL Server (linked server configuration or query plan) or (linked server configuration or query plan) or the OLE DB providerthe OLE DB provider
RowsetViewer.exeRowsetViewer.exe
25
Troubleshooting Troubleshooting (3)(3)
17803 Insufficient memory available17803 Insufficient memory available Run Instcat.sql on SQL Server 6.5Run Instcat.sql on SQL Server 6.5 Set Statistics profile onSet Statistics profile on Oracle: Q280106, Q244661Oracle: Q280106, Q244661 DB2: Q222937, Q218590, Q287093DB2: Q222937, Q218590, Q287093
26
Additional ResourcesAdditional Resources
Q203638, “HOWTO: Return Information About SQL Server Q203638, “HOWTO: Return Information About SQL Server Linked Servers”Linked Servers”
Q280106, “HOWTO: Set Up and Troubleshoot a Linked Server Q280106, “HOWTO: Set Up and Troubleshoot a Linked Server to Oracle in SQL Server”to Oracle in SQL Server”
Q207595, “HOWTO: SQL Server 7.0 Distributed Query With Q207595, “HOWTO: SQL Server 7.0 Distributed Query With FoxPro .dbf Files”FoxPro .dbf Files”
Q246255, “HOWTO: Use a SQL Server 7.0 Distributed Query Q246255, “HOWTO: Use a SQL Server 7.0 Distributed Query w/ Linked Server”w/ Linked Server”
Q314520, “HOW TO: Pass a Variable to a Linked Server Q314520, “HOW TO: Pass a Variable to a Linked Server Query”Query”
Q244661, “INF: Limitations of Microsoft Oracle ODBC Driver Q244661, “INF: Limitations of Microsoft Oracle ODBC Driver and OLEDB Provider”and OLEDB Provider”
Q197456, “INF: Optimizing Distributed Query with Numeric Q197456, “INF: Optimizing Distributed Query with Numeric Predicates”Predicates”
Q274348, “INF: Distributed Queries Executed Within a Trigger Q274348, “INF: Distributed Queries Executed Within a Trigger Enlist MSDTC”Enlist MSDTC”
27
Additional Resources Additional Resources (2)(2)
Q222937, “INF: Creating a Linked Server to DB2 w/ OLE DB Q222937, “INF: Creating a Linked Server to DB2 w/ OLE DB Provider for DB2”Provider for DB2”
Q218590, “INF: Configuring Data Sources for the Microsoft OLE Q218590, “INF: Configuring Data Sources for the Microsoft OLE DB Provider for DB2”DB Provider for DB2”
Q242025, “INF: How to Set Up Security for Linked Server to Q242025, “INF: How to Set Up Security for Linked Server to OLAP Services”OLAP Services”
Q271669, “INF: Distributed Queries are not Run as Parallel Q271669, “INF: Distributed Queries are not Run as Parallel Query Steps”Query Steps”
Q277002, “PRB: Distributed Query Against Oracle 8.x Fails”Q277002, “PRB: Distributed Query Against Oracle 8.x Fails” Q278984, “PRB: Error 7321 Occurs When You Run a Query That Q278984, “PRB: Error 7321 Occurs When You Run a Query That
Uses Four-Part Names Against DB2 on an AS/400 Computer” Uses Four-Part Names Against DB2 on an AS/400 Computer” Q270119, “PRB: 7357/7320 Error While Performing UPDATE, Q270119, “PRB: 7357/7320 Error While Performing UPDATE,
INSERT, or DELETE on Remote Table Using OpenQuery Via INSERT, or DELETE on Remote Table Using OpenQuery Via Linked Server”Linked Server”
28
Additional Resources Additional Resources (3)(3)
Q220915, “PRB: SQL Distributed Query with Oracle Needs Q220915, “PRB: SQL Distributed Query with Oracle Needs Oracle Client and Networking Components”Oracle Client and Networking Components”
Q286464, “PRB: Error 7008 Occurs When Using DB2OLEDB Q286464, “PRB: Error 7008 Occurs When Using DB2OLEDB Provider with DB2/400”Provider with DB2/400”
Q200797, “PRB: OPTIMIZER LOCK HINTS Error with Open Q200797, “PRB: OPTIMIZER LOCK HINTS Error with Open Query”Query”
Q200794, “PRB: Sp_addlinkedserver Does Not Validate the OLE Q200794, “PRB: Sp_addlinkedserver Does Not Validate the OLE DB Provider”DB Provider”
Q240340, “PRB: SQL Distributed Query w/ Oracle "Could not Q240340, “PRB: SQL Distributed Query w/ Oracle "Could not open table" Error”open table" Error”
Q306649, “PRB: Error When You Implement Nested Transaction Q306649, “PRB: Error When You Implement Nested Transaction with OLE DB Provider for SQL Provider”with OLE DB Provider for SQL Provider”
Q238477, “PRB: Message 18456 from a Distributed Query”Q238477, “PRB: Message 18456 from a Distributed Query” Q230576, “PRB: Dist. Query Involving External Provider Not Q230576, “PRB: Dist. Query Involving External Provider Not
Supported When Using Windows NT Authentication”Supported When Using Windows NT Authentication”
29
Additional Resources Additional Resources (4)(4)
Q221552, “PRB: SQL Distributed Query with Oracle NUMERIC Q221552, “PRB: SQL Distributed Query with Oracle NUMERIC Column Gives Error”Column Gives Error”
Q296685, “FIX: Cannot Execute SELECT COUNT(*) Against DB2 Q296685, “FIX: Cannot Execute SELECT COUNT(*) Against DB2 on Mainframe Using Four-Part Name”on Mainframe Using Four-Part Name”
Q281185, “FIX: Linked Index Server Query Through OLE DB Q281185, “FIX: Linked Index Server Query Through OLE DB Provider with OR Clause Reports Error 7349”Provider with OR Clause Reports Error 7349”
Q293758, “FIX: Nullability Changes Not Handled by SQL Server Q293758, “FIX: Nullability Changes Not Handled by SQL Server with Linked Server Queries to DB2”with Linked Server Queries to DB2”
Q306401, “FIX: Error Message 7355 "..Inconsistent metadata for Q306401, “FIX: Error Message 7355 "..Inconsistent metadata for a column" Occurs When You Use a Linked Server”a column" Occurs When You Use a Linked Server”
Q265865, “FIX: Float Data Inaccurately Converted When Sent to Q265865, “FIX: Float Data Inaccurately Converted When Sent to Linked Server”Linked Server”
30
Questions and AnswersQuestions and Answers
Thank you for joining today’s Microsoft SupportThank you for joining today’s Microsoft Support
WebCast.WebCast.
For information about all upcoming Support WebCasts, For information about all upcoming Support WebCasts,
and access to the archived content (streaming mediaand access to the archived content (streaming media
files, PowerPointfiles, PowerPoint®® slides, and transcripts), visit: slides, and transcripts), visit:
http://http://support.microsoft.com/webcastssupport.microsoft.com/webcasts//
Your feedback is sincerely appreciated. Please send any Your feedback is sincerely appreciated. Please send any
comments or suggestions about the Support comments or suggestions about the Support
WebCasts to WebCasts to [email protected]@microsoft.com. .