|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Checking to see if SQL Service is runningI have users who, as soon as they boot into XP, immediately try to run my
app without waiting for all of the services to start. My app uses MSDE. Is there something I can do in code to check to see if the service is running to prevent them from running the app and therefore seeing any kind of errors? Thanks. Norton Norton,
Yes you can !! You'd use System.ServiceProcess.ServiceController to check the ServiceControllerStatus Enumeration to check and see if MSDE is running or not. - Sahil Malik http://dotnetjunkies.com/weblog/sahilmalik Show quoteHide quote "TheNortonZ" <thenort***@hotmail.com> wrote in message news:#XCJYCc8EHA.2700@TK2MSFTNGP14.phx.gbl... > I have users who, as soon as they boot into XP, immediately try to run my > app without waiting for all of the services to start. My app uses MSDE. > > Is there something I can do in code to check to see if the service is > running to prevent them from running the app and therefore seeing any kind > of errors? > > Thanks. > > Norton > > BTW, you can also do this using WMI .. Select * from Win32_Service.
- Sahil Malik http://dotnetjunkies.com/weblog/sahilmalik Show quoteHide quote "TheNortonZ" <thenort***@hotmail.com> wrote in message news:#XCJYCc8EHA.2700@TK2MSFTNGP14.phx.gbl... > I have users who, as soon as they boot into XP, immediately try to run my > app without waiting for all of the services to start. My app uses MSDE. > > Is there something I can do in code to check to see if the service is > running to prevent them from running the app and therefore seeing any kind > of errors? > > Thanks. > > Norton > > TheNortonZ wrote:
> Is there something I can do in code to check to see if the service is Have a look at this.> running to prevent them from running the app and therefore seeing any kind > of errors? using System.Data.SqlClient; SqlConnection conn = new SqlConnection("connection string here"); try { conn.Open(); } catch (SqlException ex) { if (ex.Number == 17) { // Server: Msg 17, Level 16, State 1 // SQL Server does not exist or access denied } if (ex.Number == 17142) { // Server: Msg 17142, Level 16, State 1 // SQL Server has been paused. No new connection will be allowed } if (ex.Number == 18456) { // Server: Msg 18456, Level 16, State 1 // Login failed for user 'sa' } } finally { conn.Dispose(); } -- Software is like sex: it's better when it's free -- [Linus Torvalds] Fabio Marini - A+, RHCT, MCDBA, MCAD.NET To reply: news [at] mamakin1976 [dot] plus [dot] com
Other interesting topics
ObjectSpaces, object persistence
Table relations across datasets Is Whidbey the beginning of the end for the developer ? I want help with the jet 4.0 provider.. Cann't get my only record with OracleDatareader object ADO and ADO.net in the same transaction Using ADO.NET DataSet in Unmanaged C++ COM Code Several Questions on ADO.NET where can I download the ADO.Net object? Left join, cross-joined view, running forever |
|||||||||||||||||||||||