473,440 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,440 software developers and data experts.

SQL Server WHILE vs C# WHILE

I was running a small test on how WHILE loop fucntions.
this is a simple SQL code that I ran

declare @COUNTER int
set @COUNTER = 1

while @COUNTER <= 100000
begin
select @COUNTER = @COUNTER + 1
end


It took 7 seconds to run

I ran the C# equivalent which did not even take a second (fraction of second)

int counter = 1;
while (counter<= 100000)
{
counter += 1;
}


My question .... Is the WHILE in SQL Server so bad in comparison to C# one... or Am i doing smth wrong or Can I do smth to improve it...
Aug 19 '10 #1

✓ answered by ck9663

There must be something else going on with your server. I ran your code and it did not even reached 1 sec.

Happy Coding!!!

~~ CK

6 2691
ck9663
2,878 Expert 2GB
There are a lot of factors why it's slow in SQL Server. One of those factors is the optimizer. When you run it the first time, there's no execution plan for your query yet. Try running it again a couple of times after and you'll see an improvement in execution time.

Good Luck!!!

~~ CK
Aug 19 '10 #2
Ran it multiple times but did not reduce the execution time drastically... I only could get it down to 6 secs....


I even created a Stored Procedure (for execution plan sake)... and executed the stored procedure multiple times... even then the execution time stayed at 6 secs....

Thanks for your insights...
Aug 19 '10 #3
ck9663
2,878 Expert 2GB
There must be something else going on with your server. I ran your code and it did not even reached 1 sec.

Happy Coding!!!

~~ CK
Aug 19 '10 #4
Thanks for the advice...
I'm connect to my company's network using VPN....
then I connect to my Database Server to open the Management Studio...and run the query that I gave...

My understanding is that the above setup should not be an issue... there should be smth else ?
Aug 19 '10 #5
ck9663
2,878 Expert 2GB
Try connecting via RDC to your server and run it from there. The traffic could be a factor.

~~ CK
Aug 19 '10 #6
NeoPa
32,556 Expert Mod 16PB
Where did you run the C# process from?
Aug 20 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: John Spiegel | last post by:
Hi all, I'm missing something, probably stupid, on connecting to a SQL Server database from an aspx file. I haven't really done much w/ SQL Server and suspect that it's a problem on that side. ...
1
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
3
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
2
by: shanks | last post by:
I want to create a User Analysis software so in each of the webpages of that domain I want to put a very small Javascript which reports a hit on another server used just for that purpose. Is it...
0
by: Deepak Gedia | last post by:
Hi, I have created an Webservice and its work fine on local but when i have hosted on server and ... when i m accesing through my windows Application it gives me the "404 : Proxy Authentication...
1
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
3
by: =?Utf-8?B?U3JpZGhhcg==?= | last post by:
Hi, I have created a windows application to send the emails. Following is the code I am using. Dim errMsg As String Dim ToAddress As String Dim FromAddress As String Try ToAddress =...
2
by: nsaffary | last post by:
hi I hava a client/server program that run correctly when i run it in one computer(local) but when I run client on a one computer and run server run on another, connection does not stablish.(I set...
1
by: rakeshy3 | last post by:
hi, i have develop a web site on cake php. on localhost it is working properly but on remote server sessions have expires from switching one function to other. can any body provide me solutins for...
1
by: akaley | last post by:
Hi All, My system file upload functionality..iam storing file content in DataBase by using Blob data type. But my problem is MultipartRequest is automaticlly store the file in tomcat/bin...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.