473,320 Members | 2,124 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,320 software developers and data experts.

Testing that a sql server is running

My dotnet windows service, that is sampling data in real time, sits on 1
machine and the SQL server it talks to is likely to be sited on a different
pc.
The pcs are situated in an environment where there's likely to be power cuts
on a regular basis and it's never guaranteed that the client can contact the
server.
Does anyone have any code examples on how to test whether the server is up
and running or not?
thanks
Nov 17 '05 #1
6 1351
Claire wrote:
My dotnet windows service, that is sampling data in real time, sits on 1
machine and the SQL server it talks to is likely to be sited on a different
pc.
The pcs are situated in an environment where there's likely to be power cuts
on a regular basis and it's never guaranteed that the client can contact the
server.
Does anyone have any code examples on how to test whether the server is up
and running or not?
thanks

There might be a method in SQLDMO to try and connect or otherwise wrap
it in a try catch and catch whatever exception pops up when a connection
cannot be established because the server was not found.
JB
Nov 17 '05 #2
Thanks for JB's quick response.

Hi Claire,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to detect whether a SQL server
service is available. If there is any misunderstanding, please feel free to
let me know.

Based on my experience, this can be done through different approaches.

The simplest way is to create a SqlConnection object and open it. If the
open method throws an exception, it mean that the server is not available.

Another way is to use SQLDMO just as JB mentioned. In the following
example, I check for the status of a SQL server instance.

private bool ServerAvailability(string ServerName)
{
SQLDMO.SQLServer ss = new SQLDMO.SQLServerClass();
ss.Name = ServerName;
try
{
if(ss.Status == SQLDMO.SQLDMO_SVCSTATUS_TYPE.SQLDMOSvc_Running)
return true;
else
return false;
}
catch
{
return false;
}
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #3
Thank you John and Kevin :)
Nov 17 '05 #4
Of course the SqlConnection.Open could fail for more reasons than the server not being available - login failure, database not found, incorrect connection string.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
The simplest way is to create a SqlConnection object and open it. If the
open method throws an exception, it mean that the server is not available.

Nov 17 '05 #5
Thanks Richard.

You're absolutely right. I forgot to mention this in my last post. So I
provided the second way to use SQLDMO. Thanks again for point it out!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #6
You're welcome, Chaire.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #7

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

Similar topics

7
by: Bob Murdoch | last post by:
I have a fairly complicated web site with multiple sub-folders running on W2k server (IIS5?). I would like to duplicate this to another web site on the same server for testing. For instance,...
2
by: Konstantin Zakharenko | last post by:
Hello, Our QA team have running a lot of test scripts (for automated regression testing), they run them on the different databases (Oracle/MS SQL). Several of those tests are dependent on the...
5
by: btopenworld | last post by:
A couple of years ago, I had a mild hack of the default windows web page in inetpub because I was running IIS whilst my DSL connection was on. Ever since, I have disconnected the DSL before running...
7
by: cpnet | last post by:
I'm trying to stress-test some controls I've built in a sample web app using ACT. I'm now using IIS on my SBS 2k3 machine as my webserver for the test, and ACT is running on my XP Pro (sp1)...
2
by: Jeremy S. | last post by:
I have a small network running off of a SOHO switch. Last week I was connecting to my development computer from a testing computer on the same network - to test the Web app's behavior on different...
0
by: Brian Russell | last post by:
We have three servers (beyond my development box) in our organization. The first is a testing server that has IIS and SQL Server on it. The second is another testing server that also has IIS and...
1
by: Performer | last post by:
I need to test that an application using MS Access as the front end can support up to 30 concurrent users. The front end is MS Access on the client machine running Windows XP and the database is on...
18
by: Andrew Wan | last post by:
I have been developing web applications with ASP & Javascript for a long time. I have been using Visual Studio 2003.NET. While VS2003 is okay for intellisense of ASP & Javascript, it's still not...
4
by: David | last post by:
Hi list. Do test-driven development or behaviour-driven development advocate how to do higher-level testing than unit testing? types of testing: unit integration system
5
by: =?Utf-8?B?U2FsYW1FbGlhcw==?= | last post by:
Hi, I know that VS 2005 has a lot of testing features and already used them for doing web load testing. I am wondering if it is possible to load test a win forms application. I don't mean writing...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.