Не удалось запустить службу ошибка 1064

I wrote a Windows Service to run on Win10, and it worked perfectly fine until I decided to change it a bit. I rewrote some logic, tested it in both Debug and Release configurations, and everything was fine. Then I uninstalled the current version of the service using installutil.exe /u %servicename.exe% and reinstalled it again using installutil.exe %servicename.exe%.
For some reason, this new version cannot start, and it crashes with Error 1064. This is the full error text:

Windows could not start %servicename% service on Local Computer. Error 1064: An exception occurred in the service when handling the control request.

The last time I installed this service, I ran into some difficulties, but quickly fixed them by changing the Log On properties. This time, it is not working. Please help with this issue.

Thanks.

Update 1

Here are my Main() and OnStart() service methods:

Main()

static void Main()
{
#if DEBUG
    var service = new SalesforceToJiraService();
    service.OnDebug();
    Thread.Sleep(Timeout.Infinite);
#else
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[]
    {
        new SalesforceToJiraService()
    };
     ServiceBase.Run(ServicesToRun);
#endif
}

OnStart()

protected override void OnStart(string[] args)
{
    this.ConfigureServices();

    this.timer.Start();
    this.logger.Information("SalesforceToJira service started.");
}

Update 2

More code:

ConfigureServices()

protected void ConfigureServices()
{
    this.configuration = ConfigurationHelper.LoadConfiguration(ConfigurationPath);
    this.logger = ConfigurationHelper.ConfigureLogger(this.configuration.Logs.LogsPath);

    this.timer = ConfigurationHelper.ConfigureTimer(this.configuration.ProcessInterval.TotalMilliseconds,
        (sender, eventArgs) => this.ProcessCasesAsync(sender, eventArgs).GetAwaiter().GetResult());

    this.salesforceClient = new SalesforceCliClient(this.configuration.Salesforce.CliPath);

    this.jiraClient = Jira.CreateRestClient(
        this.configuration.Jira.Url,
        this.configuration.Jira.Username,
        this.configuration.Jira.Password);
}

I’m using Newtonsoft.JSON for deserializing a JSON configuration file, Serilog for logging, System.Timers.Timer for periodic events, AtlassianSDK for the Jira API and some wrappers over Salesforce CLI for Salesforce.

veeam

Veeam Backup & Replication is comprehensive data protection and disaster recovery solution that provides a centralized console for administering backup, restore, and replication operations in all supported platforms (virtual, physical, cloud). Regardless of what your needs are ranging from flexible hybrid cloud capabilities from AWS, Azure, and Google Cloud, or the most robust ransomware protection and recovery options. Kindly refer to these related guides: Veeam Certified Architect: A review of the VMCA Training & Certification, how to set up Veeam ONE 11 Server, how to uninstall Veeam Backup and Replication from your server, and how to set up Veeam Backup for Microsoft Azure [Part 1].

Here is the Eror message "Error 1064: An exception occurred in the service when handling the control request: No connection can be made because the active machine rejected it".

Veeam brings hardened immutable storage options, dependable cloud-native backup options, Continuous Data Protection, and much more all under one platform, with a single portable license for all workloads. I created this blog post due to the following error described in this guide “Windows could not start the SQL Server service on local computer 17051: A network-related or instance-specific error occurred while establishing a connection to SQL Server“.

Kindly refer to these related guides:

  • How to install MSSQL Server 2019 Developer Edition and SSMS on Windows, and
  • How to download and install Microsoft SQL Server 2019 Express edition and SSMS, and
  • The server was not found or was not accessible: A network-related or instance-specific error occurred while establishing a connection to SQL Server.

The following is a related error “Failed to connect to Veeam Backup & Replication Server: No connection could be made because the target machine actively refused it“. Even when you try to start the service, it does not start and it fails with the following error.

Error 1064-1

Error 1064

Reason for the error

This is because the evaluation period of 180 days has expired. Kindly refer to this guide on MSSQL licensing: How to upgrade SQL Server instance. Also, I decided to take a look at the log as shown below. Microsoft Windows servers, logs are stored in the following directory: %ProgramData%\Veeam\Backup. On a Linux machine, and ESXi hosts, logs are stored in the following directory: /var/log/VeeamBackup/ or /tmp/VeeamBackup.

Screenshot-2022-02-24-at-23.12.23

[21.02.2022 21:59:45] <04> Info         [DB] Connecting to SQL Server (CurrentUser=[TECHDIRECTARCHI\Christian], ServerInstance=[MBAMSERV1\MBAM], Options=[Direct])
[21.02.2022 21:59:45] <04> Info         [DB] Removing 'Initial Catalog' property from connection string
[21.02.2022 22:01:45] <04> Info         [DB|ERROR] Failed to connect to server . (Microsoft.SqlServer.Management.Common.ConnectionFailureException)
[21.02.2022 22:01:45] <04> Info         [DB|ERROR]    at Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()
[21.02.2022 22:01:45] <04> Info         [DB|ERROR]    at Veeam.Backup.DBCreator.DatabaseConnector.Connect(DatabaseConnectorOptions options)
[21.02.2022 22:01:45] <04> Info         [DB|ERROR] A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (System.Data.SqlClient.SqlException)

As you can see below, the SQL Server service isn’t running.

start sql server service

Upon resolving this issue by upgrading the SQL Server instance, I was now able to start the service as shown below. Kindly refer to these related guides: How to install MSSQL Server 2019 Developer Edition and SSMS on Windows, and how to download and install Microsoft SQL Server 2019 Express edition and SSMS.

sql server service is running

Yet, the Veeam Backup and Replication console could not be started with the following error “Failed to connect to the Backup and Replication Server - No connection can be made because the active machine rejected it".

Screenshot-2022-02-24-at-18.56.16

To fix these issues, you will need to grant the Veeam Backup Service local administrative rights. For me, the local system account did not work.

Note: The account used to run the Veeam Backup Service must be a LocalSystem account or must have local Administrator permissions on the backup server.

Screenshot-2022-02-24-at-21.39.10

Upon granting these rights, I was able to start the Veeam Backup and Replication Console. The console allows you to automate and schedule routine data protection operations and integrate with solutions for alerting and generating compliance reports.

I hope you found this blog post helpful. If you have any questions, please let me know in the comment session.

Hi,

I’m running into a little behavior that I cannot explain. I’ve build a C# Service that watches the Security EventLog for specific events and generates a little report based on them. 

The application runs on a Windows 2008 R2 Standard Server with .NET 4.8 installed. The target framework is .NET 4.7.2 and the service runs as Local System. 

So far the application works like a charm but… in the wrong folder and I seem unable to change it. The default folder is «C:\Windows\SysWow64\», normal for a 32-bits service. But I’d like to point it to another folder «C:\TestApps\EventLogGuard»
as a working directory. 

I’ve tried to change the working directory or path it writes files to in two ways (both resulting in the same error):

1. By changing the working directory

string path = @"C:\TestApps\EventLogGuard";
Directory.SetCurrentDirectory(path);

2. By changing the path I’m writing to in a streamwriter to:

string fileName = @"C:\TestApps\EventLogGuard\IPList.txt"; string fileLog = @"C:\TestApps\EventLogGuard\EventLogGuard.log";

using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName))
{

~~~~~~

}

As soon as either option is added I’m getting an error 1064 on-start. In the Windows EventLog I can see the following error displayed:

Problem signature:
P1: EventLogGuardSVC.exe
P2: 1.0.0.0
P3: f8080359
P4: mscorlib
P5: 4.8.3761.0
P6: 5c9c6e98
P7: 168e
P8: fc
P9: System.IO.DirectoryNotFound
P10: 

Does anyone have an idea what may be causing this behavior or experienced something similar? 

Edit: The directory exists and I do have a check added if the path exists as well, makes no difference.

  • Edited by

    Friday, October 25, 2019 8:44 AM

The error «Could not start Windows Service, Error 1064» occurs when attempting to start a Windows Service built in C#. This error can have multiple causes, including syntax errors in the SQL statement being executed, or incorrect parameters being passed to the service. In this guide, we’ll outline several methods to help resolve this issue and get your service up and running smoothly again.

Method 1: Check SQL Syntax

To fix the «Could not start Windows Service, Error 1064» error in C#, you can use the «Check SQL Syntax» method. This method checks the syntax of the SQL code to ensure that it is correct and free of errors. Here are the steps to follow:

  1. Define a string variable to hold the SQL query.
string sqlQuery = "SELECT * FROM Customers WHERE Country = 'USA'";
  1. Create a SqlConnection object to connect to the database.
SqlConnection connection = new SqlConnection("Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=True");
  1. Create a SqlCommand object to execute the SQL query.
SqlCommand command = new SqlCommand(sqlQuery, connection);
  1. Use the SqlCommandBuilder object to generate the SQL syntax.
SqlCommandBuilder builder = new SqlCommandBuilder(command);
string sqlSyntax = builder.GetInsertCommand().CommandText;
  1. Use the SqlConnection object to check the syntax of the SQL code.
connection.Open();
SqlCommand checkSyntax = new SqlCommand("SET PARSEONLY ON; " + sqlSyntax + " SET PARSEONLY OFF;", connection);
checkSyntax.ExecuteNonQuery();
connection.Close();
  1. If there are no errors, execute the SQL query.
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
    Console.WriteLine(reader["CustomerName"].ToString());
}
connection.Close();

Here is the complete code:

string sqlQuery = "SELECT * FROM Customers WHERE Country = 'USA'";
SqlConnection connection = new SqlConnection("Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=True");
SqlCommand command = new SqlCommand(sqlQuery, connection);
SqlCommandBuilder builder = new SqlCommandBuilder(command);
string sqlSyntax = builder.GetInsertCommand().CommandText;
connection.Open();
SqlCommand checkSyntax = new SqlCommand("SET PARSEONLY ON; " + sqlSyntax + " SET PARSEONLY OFF;", connection);
checkSyntax.ExecuteNonQuery();
connection.Close();
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
    Console.WriteLine(reader["CustomerName"].ToString());
}
connection.Close();

This method ensures that the SQL code is correct and free of errors before executing it, which can help prevent the «Could not start Windows Service, Error 1064» error.

Method 2: Debug Service Startup

To debug a Windows service startup, you can use the Debugger.Break() method to break into the debugger at the start of the service. Here are the steps to do this:

  1. Open the project in Visual Studio.
  2. In the Solution Explorer, right-click the service project and select Properties.
  3. In the Properties window, select the Debug tab.
  4. In the Start Options section, set the Command line arguments to --debug.
  5. In the Start Options section, check the box for «Enable native code debugging».
  6. In the Start Options section, uncheck the box for «Enable Just My Code».
  7. In the Start Options section, set the Start action to «Start external program» and specify the path to the sc.exe tool (usually located in C:\Windows\System32\sc.exe).
  8. In the Start Options section, set the Working directory to the folder where the sc.exe tool is located.
  9. Save the changes to the project properties.

Now, when you start the service from the Services control panel, the sc.exe tool will start the service with the --debug command line argument, which will cause it to break into the debugger at the start of the service.

Here is an example of how to use the Debugger.Break() method in the OnStart() method of a Windows service:

protected override void OnStart(string[] args)
{
    Debugger.Break(); // break into the debugger
    // your service startup code here
}

This will cause the service to break into the debugger at the start of the OnStart() method, allowing you to step through your code and debug any issues that may be causing the service to fail to start.

Another option is to use the Debugger.Launch() method instead of Debugger.Break(). This will launch a new instance of Visual Studio and attach the debugger to the service process, allowing you to debug the service as if it were a normal application.

protected override void OnStart(string[] args)
{
    Debugger.Launch(); // launch the debugger
    // your service startup code here
}

Note that using Debugger.Launch() can be more intrusive and may cause issues if the service is running on a remote machine, so use it with caution.

I hope this helps you solve the «Could not start Windows Service, Error 1064» issue with «Debug Service Startup».

Method 3: Verify Service Settings

Verify Service Settings

One of the possible solutions to fix «Could not start Windows Service, Error 1064» is to verify the service settings. Here are the steps to do it:

  1. Open the Services Manager by typing «services.msc» in the Run dialog box or by searching for «Services» in the Start menu.

  2. Find the service that is causing the error and right-click on it. Select «Properties» from the context menu.

  3. In the Properties dialog box, go to the «Log On» tab.

  4. Check if the «Log on as:» option is set to «Local System account». If not, select it and click on the «Apply» button.

  5. Go to the «Recovery» tab.

  6. In the «First failure», «Second failure», and «Subsequent failures» drop-down lists, select «Restart the Service».

  7. Click on the «Apply» button and then on the «OK» button to save the changes.

Here is an example code to verify the service settings programmatically in C#:

using System.ServiceProcess;

// ...

ServiceController sc = new ServiceController("ServiceName");

if (sc.StartType != ServiceStartMode.Automatic)
{
    sc.StartType = ServiceStartMode.Automatic;
    sc.Refresh();
}

ServiceRecoveryOptions sro = sc.ServiceRecoveryOptions;

if (sro.FirstFailureAction != ServiceRecoveryAction.RestartService)
{
    sro.FirstFailureAction = ServiceRecoveryAction.RestartService;
    sro.SecondFailureAction = ServiceRecoveryAction.RestartService;
    sro.SubsequentFailuresAction = ServiceRecoveryAction.RestartService;
    sro.Refresh();
}

This code checks if the service’s start type is set to «Automatic» and if not, sets it to «Automatic». It also sets the service recovery options to restart the service on the first, second, and subsequent failures.

I hope this helps you to fix the «Could not start Windows Service, Error 1064» issue with the «Verify Service Settings» method.

Method 4: Repair .NET Framework Installation

To fix the «Could not start Windows Service, Error 1064» issue in C#, one of the methods is to repair the .NET Framework installation. Here are the steps to do so:

  1. Open the Control Panel and go to Programs and Features.
  2. Find the Microsoft .NET Framework installation in the list and right-click on it.
  3. Choose the «Change» option and follow the prompts to repair the installation.

Here is an example code snippet to check if the .NET Framework is installed and which version is installed:

using System;
using Microsoft.Win32;

class Program
{
    static void Main(string[] args)
    {
        // Check if the .NET Framework is installed
        bool isInstalled = IsDotNetFrameworkInstalled();
        Console.WriteLine(".NET Framework is installed: " + isInstalled);

        // Get the version of the .NET Framework
        string version = GetDotNetFrameworkVersion();
        Console.WriteLine(".NET Framework version: " + version);
    }

    static bool IsDotNetFrameworkInstalled()
    {
        // Check if the .NET Framework is installed by looking for the registry key
        RegistryKey dotNetKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework");
        return dotNetKey != null;
    }

    static string GetDotNetFrameworkVersion()
    {
        // Get the version of the .NET Framework from the registry key
        RegistryKey dotNetKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework");
        string version = dotNetKey.GetValue("InstallRoot") + "v" + dotNetKey.GetValue("Version");
        return version;
    }
}

Note that this code only checks if the .NET Framework is installed and which version is installed. To repair the installation, follow the steps outlined above.

Target Audience: IT Manager
Article #: 12190

Summary

When trying to launch TEKLYNX CENTRAL right after installing, the user received the Windows Service error message: Windows could not start the TkxSvr Servers Service service on Local Computer. Error 1064: An exception occurred in the service when handling the control request.” This article explains the error message and why Windows could not start the service.

Windows Services Error 1064 message.

Explanation

The “Windows could not start the TkxSvr Servers Service service on Local Computer. Error 1064..” was actually the second error message. The first message read, “Unhandled exception has occurred. Failed to establish connection to the server…”

This is the same Local System account that was was used during the install of TEKLYNX CENTRAL. However, it appears that this account was does not have the permissions needed to run these two services.

Quick Fixes

Change the Log On credentials to an account that has sufficient permissions. We used a Domain Admin account.

Log On for TkxSvr Servers Service

If credentials aren’t the issue, licensing and drive space issues are other causes of this error message.

Issue found: TEKLYNX CENTRAL v6.0 running on Windows Server 2016

If you need further assistance, please contact us.

Dave Klement

Principal at Efficient Business Systems

Понравилась статья? Поделить с друзьями:

Интересное по теме:

  • Не удалось запустить службу защитника windows ошибка 577
  • Не удалось запустить службу журнал событий ошибка 4201
  • Не удалось инициализировать подключение к 1с ошибка mse1004
  • Не удалось открыть документ ошибка декодирования
  • Не удалось запустить службу диспетчер печати ошибка 1068

  • Добавить комментарий

    ;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: