Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > สอบถามเรื่องการ Check Status SQL Server หน่อยครับ ว่ามีกี่วิธี



 

สอบถามเรื่องการ Check Status SQL Server หน่อยครับ ว่ามีกี่วิธี

 



Topic : 100467

Guest




ผมทำระบบระบบหนึ่ง
เวลา SQLSERVER มัน online ก็ให้มันเก็บลง Sql ปกติ
แต่พอเวลามันหลุด หรือว่า SQL down มันจะเช็คยังไงไห้เร็วๆว่า sql มีปัญหาอะครับ พอเช็คแล้วจะเก็บลงแบบ offline

สรุปคือ
จะเช็คยังไงว่า Server เราไม่ดาว
- ผมเช็คโดย con.connectionstate กว่ามันจะตอบกลับมา นานมากๆ

พอมีวิธีอย่างอื้นไหมครับ



Tag : .NET, VS 2010 (.NET 4.x), VS 2012 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-09-14 18:00:09 By : ghack View : 1003 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (VB.NET)
Imports System
Imports System.ServiceProcess

Module Module1

    Sub Main()

        Dim myServiceName As String = "MSSQL$SQLEXPRESS" 'service name of SQL Server Express
        Dim status As String  'service status (For example, Running or Stopped)
        Dim mySC As ServiceController

        Console.WriteLine("Service: " & myServiceName)

        'display service status: For example, Running, Stopped, or Paused
        mySC = New ServiceController(myServiceName)
        Try
            status = mySC.Status.ToString
        Catch ex As Exception
            Console.WriteLine("Service not found. It is probably not installed. [exception=" & ex.Message & "]")
            Console.ReadLine()
            End
        End Try
        Console.WriteLine("Service status : " & status)

        'if service is Stopped or StopPending, you can run it with the following code.
        If mySC.Status.Equals(ServiceControllerStatus.Stopped) Or mySC.Status.Equals(ServiceControllerStatus.StopPending) Then
            Try
                Console.WriteLine("Starting the service...")
                mySC.Start()
                mySC.WaitForStatus(ServiceControllerStatus.Running)
                Console.WriteLine("The service is now " & mySC.Status.ToString)

            Catch ex As Exception
                Console.WriteLine("Error in starting the service: " & ex.Message)
            End Try
        End If

        Console.WriteLine("Press a key to end the application...")
        Console.ReadLine()
        End
    End Sub
End Module


Code (C#)
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceProcess;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {

            string myServiceName = "MSSQL$SQLEXPRESS"; //service name of SQL Server Express
            string status; //service status (For example, Running or Stopped)

            Console.WriteLine("Service: " + myServiceName);

            //display service status: For example, Running, Stopped, or Paused
            ServiceController mySC = new ServiceController(myServiceName);

            try
            {
                status = mySC.Status.ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Service not found. It is probably not installed. [exception=" + ex.Message + "]");
                Console.ReadLine();

                return;

            }

            //display service status: For example, Running, Stopped, or Paused
            Console.WriteLine("Service status : " + status);

            //if service is Stopped or StopPending, you can run it with the following code.
            if (mySC.Status.Equals(ServiceControllerStatus.Stopped) | mySC.Status.Equals(ServiceControllerStatus.StopPending))
            {
                try
                {
                    Console.WriteLine("Starting the service...");
                    mySC.Start();
                    mySC.WaitForStatus(ServiceControllerStatus.Running);
                    Console.WriteLine("The service is now " + mySC.Status.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error in starting the service: " + ex.Message);

                }

            }

            Console.WriteLine("Press a key to end the application...");
            Console.ReadLine();

            return;

        }

    }
}

http://support.microsoft.com/kb/912426/th







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-09-16 09:16:54 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามเรื่องการ Check Status SQL Server หน่อยครับ ว่ามีกี่วิธี
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่