日期:2014-05-20  浏览次数:21071 次

请高手回答一个关于C#的问题,谢谢了!
在C#中如何判断MSsql2005是否已启动?
希望能给点源代码,最好能有解释,谢谢!

------解决方案--------------------
C# code
private void StartService(string serviceName)
        {
            if (ServiceIsExisted(serviceName))
            {
                System.ServiceProcess.ServiceController service = new System.ServiceProcess.ServiceController(serviceName);
                if (service.Status != System.ServiceProcess.ServiceControllerStatus.Running && service.Status != System.ServiceProcess.ServiceControllerStatus.StartPending)
                {
                    service.Start();
                    for (int i = 0; i < 60; i++)
                    {
                        service.Refresh();
                        System.Threading.Thread.Sleep(1000);
                        if (service.Status == System.ServiceProcess.ServiceControllerStatus.Running)
                        {
                            break;
                        }
                        if (i == 59)
                        {
                            throw new Exception(startServiceError.Replace("$s$", serviceName));
                        }
                    }
                }
            }
        }

------解决方案--------------------
telnet IP:1433
------解决方案--------------------
连接在呢么那个样子???
再写下

http://msdn.microsoft.com/en-us/library/system.data.sql.sqldatasourceenumerator.getdatasources.aspx