Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQL Server服务不是由代码启动的_C#_Sql Server_Service - Fatal编程技术网

C# SQL Server服务不是由代码启动的

C# SQL Server服务不是由代码启动的,c#,sql-server,service,C#,Sql Server,Service,我需要一个能自动启动机器上SQL实例的服务。到目前为止还不错,我可以让它们都工作,但当我在一台装有Windows7的机器上运行时,我得到了一个错误1053(超时)。但将超时更改为180000,错误仍在继续 我在Windows 10中执行相同的过程,并在SQL Express 2005、2008和2012的实例上100%运行 我不能确定问题是否真的是Windows 7或SQL Server 2005,即此Windows 7中的问题。如果我手动启动此过程,它将正常启动 代码: 使用cmd和net s

我需要一个能自动启动机器上SQL实例的服务。到目前为止还不错,我可以让它们都工作,但当我在一台装有Windows7的机器上运行时,我得到了一个错误1053(超时)。但将超时更改为180000,错误仍在继续

我在Windows 10中执行相同的过程,并在SQL Express 2005、2008和2012的实例上100%运行

我不能确定问题是否真的是Windows 7或SQL Server 2005,即此Windows 7中的问题。如果我手动启动此过程,它将正常启动

代码:


使用cmd和net start xxxx命令也可以工作。

mcs将以您的用户身份运行,这与此服务运行的用户不同。导航到服务右键单击>属性,并将用户从本地计算机更改为具有访问权限的计算机。请尝试您的用户,看看这是否比安全问题更有效

我解决了在服务中插入依赖项的问题

this.serviceInstaller.ServicesDependedOn = SqlServerServiceHelper.GetInstances().Select(x => x.ServiceName).ToArray();


public static ServiceController[] GetInstances()
{
     ServiceController[] services = ServiceController.GetServices().Where(x => x.ServiceName.Contains("SQL")).ToArray();
     var servicesToRemove = services.Where(x => x.DisplayName.Contains("Agent") ||
                                           x.DisplayName.Contains("Browser") ||
                                           x.DisplayName.Contains("VSS") ||
                                           x.DisplayName.Contains("Active")).ToArray();
     return services.Except(servicesToRemove).ToArray();
}

运行此服务的用户是否具有启动和停止服务的安全权限?如何以管理员权限执行services.msc?在Windows 10上,这不是必需的吗?但在W10上工作。我将在这里测试这个,大约2小时。我正在格式化笔记本,并将再次安装,以查看是否无法正常工作,请按您所说的操作。以管理员身份运行,但没有任何效果。
this.serviceInstaller.ServicesDependedOn = SqlServerServiceHelper.GetInstances().Select(x => x.ServiceName).ToArray();


public static ServiceController[] GetInstances()
{
     ServiceController[] services = ServiceController.GetServices().Where(x => x.ServiceName.Contains("SQL")).ToArray();
     var servicesToRemove = services.Where(x => x.DisplayName.Contains("Agent") ||
                                           x.DisplayName.Contains("Browser") ||
                                           x.DisplayName.Contains("VSS") ||
                                           x.DisplayName.Contains("Active")).ToArray();
     return services.Except(servicesToRemove).ToArray();
}