Solved

Linked Server stored procedure running VERY SLOW

Posted on 2003-12-04
5
733 Views
Last Modified: 2006-11-17
I have two servers, each running win2k advance, and sql server 2000 enterprise.  Service pack 3 on both SQL Servers.  If I run the following query, I get the results back instantly

select * from linkserver.db.dbo.table where pk = 1

but if I run

declare @pk int
set @pk = 1
select * from linkserver.db.dbo.table where pk = @pk

it takes 7 minutes to return.  Any ideas what the problem is?  


0
Comment
Question by:kprestage
  • 3
  • 2
5 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 9876787
what is the column type of the pk column


have you tried an openquery query instead?

 
0
 
LVL 9

Author Comment

by:kprestage
ID: 9876852
The parameter is an int data type and the column on the table is int too.  Open query wont work in this situation.  I need to get it working as a linked server.
0
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 500 total points
ID: 9876908
how long does

declare @pk int
set @pk = 1
declare @sqlstr varchar(8000)
set @sqlstr =
'select * from linkserver.db.dbo.table where pk =' + convert(varchar(10), @pk)
exec (@sqlstr)

take?

0
 
LVL 9

Author Comment

by:kprestage
ID: 9876936
less than 1 second
0
 
LVL 9

Author Comment

by:kprestage
ID: 9877106
LowFatSpread...

You didnt fix my problem, but I appreciate the help!  I think I found the solution...  The linked server were set up using the SQL Server option rather than the OLEDB Provider for SQL Server.   I created a new linked server and selected OLEDB Provider for SQL Server and then click on Provider Properties.  I set the checkbox for dynamic parameters = true for the provider, clicked apply, and then cancelled adding the new linked server.  Making that change fixed the problem on my existing linked servers!  Thanks again for your help.  
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now