473,611 Members | 2,242 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling SQL from code has different behaviour than calling it from MS SQL Server Management Studio

HI

I am experiencing something funny here where I have two equivalent
queries: If I run them through query analyzer, the first runs slower
than the second, but if run through C# application, the first runs
faster than the second.

I have the following two equivalent versions of a query which I will
present in psuedo code:

-------------------------
(1) Simple JOIN of two SELECT statements

SELECT Col1 FROM
(
SELECT table1.Col1 FROM table1 WHERE exp1
JOIN
SELECT table1.Col1 FROM table2 WHERE exp2
ON table1.Col1 = table2.Col1
)

-------------------------
(2) I create temporary tables, JOIN them and then DROP them.

-- Create Temp tables
SELECT table1.Col1
INTO #temp_table1
FROM table1 WHERE exp1

SELECT table1.Col1
INTO #temp_table2
FROM table2 WHERE exp2

-- JOIN the temp tables
SELECT Col1 FROM
(
#temp_table1
JOIN
#temp_table2
ON #temp_table1.Co l1 = #temp_table2.Co l1
)

-- DROP the tamp tables
DROP Table #temp_table1
DROP Table #temp_table2

-------------------------

If I run (1) from the query analyzer in MS SQL Server Management
Studio, it runs slower than (2). I clear the SQL server cache before
each call.

If I run (1) from the C# test application, it runs faster the (2) from
the same C# test app. I use .Net 2.0 using the System.Data.Sql Client
calls.

The way I can see the different in execution times is through the SQL
server profiler.

Can anybody explain that?
Any help would be much appreciated

Thank you in advance
Jeeji

Jun 29 '06 #1
1 1748
Hi again

I found out what was wrong. I did not clear the cache from the C# code,
which is obviously necessary .Sorry for the disturbance

Jeeji

jeeji skrev:
HI

I am experiencing something funny here where I have two equivalent
queries: If I run them through query analyzer, the first runs slower
than the second, but if run through C# application, the first runs
faster than the second.

I have the following two equivalent versions of a query which I will
present in psuedo code:

-------------------------
(1) Simple JOIN of two SELECT statements

SELECT Col1 FROM
(
SELECT table1.Col1 FROM table1 WHERE exp1
JOIN
SELECT table1.Col1 FROM table2 WHERE exp2
ON table1.Col1 = table2.Col1
)

-------------------------
(2) I create temporary tables, JOIN them and then DROP them.

-- Create Temp tables
SELECT table1.Col1
INTO #temp_table1
FROM table1 WHERE exp1

SELECT table1.Col1
INTO #temp_table2
FROM table2 WHERE exp2

-- JOIN the temp tables
SELECT Col1 FROM
(
#temp_table1
JOIN
#temp_table2
ON #temp_table1.Co l1 = #temp_table2.Co l1
)

-- DROP the tamp tables
DROP Table #temp_table1
DROP Table #temp_table2

-------------------------

If I run (1) from the query analyzer in MS SQL Server Management
Studio, it runs slower than (2). I clear the SQL server cache before
each call.

If I run (1) from the C# test application, it runs faster the (2) from
the same C# test app. I use .Net 2.0 using the System.Data.Sql Client
calls.

The way I can see the different in execution times is through the SQL
server profiler.

Can anybody explain that?
Any help would be much appreciated

Thank you in advance
Jeeji


Jun 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3138
by: ZeBerg | last post by:
Is it possible to have a stored procedure in database A while calling it from database B and have it manipulate the tables in database B (whatever the calling database happens to be)? We have a large-scale app that uses many complex stored procedures, and as of now, we're copying the SPs to every new database that is created, and it will soon become a nightmare for propagating updates and fixes. We'd like to keep a master set of the SPs...
8
17468
by: Glenn A. Harlan | last post by:
Why am I receiving the below error when calling - Path.GetTempFileName() The directory name is invalid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.IOException: The directory name is invalid.
15
11757
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that performs the query is contained in a delegate function that I execute via a second thread. On 1 or 2 of the 600+ servers the query hangs. I've tried to use Thread.Join() coupled with a Thread.Abort() but this does not kill the thread. Based on...
171
7685
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
4
1836
by: Learner | last post by:
we can download the Management Studio Express for free from MS website. I did the same thing on my personal laptop. But can we develop applications using free downloaded Management Studio and deploy later on with the free stuff at work? Or else may i want to get it off Sql server 2005 that we got when we bought the software.
14
7023
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that sql server resides on is not reachable. The error is different depending on the connection string that I use. If I use the following connection string: "server=192.1.1.1; Initial Catalog=master; uid=The_User; password=The_Password; Connect...
1
2542
by: theintrepidfox | last post by:
Dear Group. Wondered if any of you has any suggestion for the following? Trying to install SQL Server 2005 Eval on a 'clean' machine. Well, my mistake was probably that I had installed Visual Studio 2005 Professional Eval before which installed an MSSQL Express instance. Since then I didn't get 'Enterprise Manager' (excuse my ignorance, I know it's called differently in2005 but it's late and I'm tired) for MSSQL 2005 installed.Don't...
2
1169
by: mariuszb | last post by:
I use job executing stored procedures to get data for OLAP. All works fine except one thing: one of the procedures takes a few hours to complete. Executing procedure via remote desktop and query analyzer directly on the server gives the same behaviour. Same procedure executed from query analyzer/management studio from PC works fine - executes in about five minutes. SQL server 2k. SP has set nocount, estimated execution plans have same...
2
2835
by: Robert | last post by:
I'm a newbie trying to find the SQL Server Enterprise Manager so I can create a database. I have installed SQL Server 2005 Express and SQL Server Management Studio Express. On the SQL Server menu I see (1) Configuration Tools and (2) SQL Server Management Studio Express. The SQL Server Management Studio Express menu has 3 items on it. Where do I find the Enterprise Manager? Robert
0
8149
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8561
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7038
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4042
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4108
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.