I am getting below error while running windows service: The "my service name" service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other service or programs"
It is difficult to track down this type of generic errors. You can do the following options to figure out the issue and fix it. Option 1: With Event viewer you can see the errors and on which line number we are getting it. Do the following steps to open the Event Viewer:
1) Type Event Viewer on start and click it.
2) In popup look for “Windows Logs” under “Event Viewer (Local)” on left panel and click it.
3) Now you will get list of windows logs, select “Application” from it.
Here you can search for error, see the screen shot below:
Option 2: You can have try catch blog with logging errors to table.
I have created a small function to log error as below:
public static void getLog(string msg)
string query = "insert into LOGTABLE (DATE,LEVEL,MESSAGE,EXCEPTION) values(current_timestamp,'INFO','"+msg+"','-')";
var DB = dbConnect();
command = new SqlCommand(query, DB);
dataReader = command.ExecuteReader();
Add more try/catch blocks and logging to the app to get a better picture of what’s going on.
Hope it helps someone!!!
In this post, I am sharing how you can install or uninstall windows services in your local windows system [Windows 10]. Assuming you already built one windows services using C# and want to install it using the command prompt. Follow the below steps to install on your local windows 10 environment:
Step 1: Before you install a windows services you need to generate EXE file. And for generating you need to go to the Visual studio and clean and build your application, which will automatically generate exe file in bin folder.
Step 2: Open command prompt “as Administrator”
Step 3: Navigate to folder “C:\Windows\Microsoft.NET\Framework\v4.0.30319>”
Step 4: For installing you need to run below command: installutil.exe "E:\Suresh\Projects\TestWindowsService\TestWindowsService\obj\Debug\TestWindowsService.exe"
Step 5: Open Run window (Window + R), type in “services.msc”, and press enter. A “Services” popup will open. Step 6: In “Services” popup search for your service name and start it by right click on it.
Thats All !!!
Now If you want to uninstall it, type the following command:
installutil.exe -u “E:\Suresh\Projects\TestWindowsService\TestWindowsService\obj\Debug\TestWindowsService.exe”
After deploying to IIS server from Visual Studio getting below error,
Could not load file or assembly 'System.Web.Http.WebHost, Version=184.108.40.206, Culture=neutral,PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file
You can fixed by either of below steps: Option 1: To Resolve issue you have to move “System.Web.Http.WebHost.dll” file in “bin” folder to IIS. And restart the server to reload everything again. Check the site should work. Option 2: Follow below steps:
1) Go to “Solution Explorer” in Visula Studio.
2) Right Click on “System.Web.Http.WebHost” in “References” and select properties.
3) Update property “Local Copy” to “True”.
4) Clear and Build again to have DLL in bin folder.
5) Copy the “System.Web.Http.WebHost.dll” file in “bin” folder to IIS.
Application should work.
I am getting below errors (one after the another build) so I repeated the steps to update “Local Copy” to “True” and build and copied the DLL to IIS, it started working.
Could not load file or assembly 'System.Net.Http.Formatting, Version=220.127.116.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Web.Http, Version=18.104.22.168, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Here I am sharing how you can read excel file using EPPlus package. Many solution given on internet but nothing work for me, so I thought of sharing what worked for me.
In below example method required excel file name (full server path) and then it will read first sheet of the workbook. You can modify it according to your requirement.
public void readXLS(string FilePath)
FileInfo existingFile = new FileInfo(FilePath);
using (ExcelPackage package = new ExcelPackage(existingFile))
//get the first worksheet in the workbook
ExcelWorksheet worksheet = package.Workbook.Worksheets;
int colCount = worksheet.Dimension.End.Column; //get Column Count
int rowCount = worksheet.Dimension.End.Row; //get row count
for (int row = 1; row <= rowCount; row++)
for (int col = 1; col <= colCount; col++)
Console.WriteLine(" Row:" + row + " column:" + col + " Value:" + worksheet.Cells[row, col].Value.ToString().Trim());
If you want to insert excel data into table you can refer to my blog: