Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7609087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:05:11+00:00 2026-05-31T01:05:11+00:00

thanks for reading my post i am programming a Windows Service, and when i

  • 0

thanks for reading my post i am programming a Windows Service, and when i try to start it i get this error on the EventViewer:

Application: SerivicioBIOHAcademico.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Security.SecurityException
Stack:
   at System.Diagnostics.EventLog.FindSourceRegistration(System.String, System.String, Boolean, Boolean)
   at System.Diagnostics.EventLog.SourceExists(System.String, System.String, Boolean)
   at System.Diagnostics.EventLog.SourceExists(System.String)
   at SerivicioBIOHAcademico.BIOHAcad..ctor()
   at SerivicioBIOHAcademico.Program.Main()

Here is some code from my Service App (C#)

public partial class BIOHAcad : ServiceBase
    {
        Timer timer1 = new Timer();
        private readonly string WDcon = ConfigurationManager.ConnectionStrings["WindowsFormsApplication2.Properties.Settings.DBGriauleConnectionString"].ConnectionString;
        private readonly string UJGH = ConfigurationManager.ConnectionStrings["HorariosConnection"].ConnectionString;

        public BIOHAcad()
        {
            InitializeComponent();
            if (!System.Diagnostics.EventLog.SourceExists("Fuentes-BIO-H-Academico"))
            {
                System.Diagnostics.EventLog.CreateEventSource(
                   "Fuentes-BIO-H-Academico", "Logs-BIO-H-Academico");
            }
            eventLog1.Source = "Fuentes-BIO-H-Academico";
            eventLog1.Log = "Logs-BIO-H-Academico";
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                eventLog1.WriteEntry("Iniciando Servicio BIO-H Academico");
                timer1.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
                timer1.Interval = 1000;
                timer1.Enabled = true;
                timer1.Start();
            }
            catch (Exception e)
            {
                eventLog1.WriteEntry(e.ToString());
            } 
        }

        private void timer1_Elapsed(object sender, EventArgs e)
        {
            try
            {
                Buscar_Horarios(DateTime.Now);
            }
            catch (Exception ex)
            {
                eventLog1.WriteEntry(ex.ToString());
            }
        }

        private void Buscar_Horarios(DateTime fecha)
        {
            bool conectarse = Conectarse_BD();
            if (conectarse == true)
            {
                DateTime corte = fecha.AddMinutes(((-1) * Holgura_Academica()));
                string dia = Funciones.ObtenerDiaSemana2(fecha);
                string hora = Funciones.ObtenerHora(fecha);
                string cortedia = Funciones.ObtenerHora(corte);
                //Llamo la conexion SQL
                SqlConnection Wdcon_usuario = new SqlConnection(UJGH);
                SqlCommand usuario = new SqlCommand();
                SqlDataReader usuarioDR = null;

                //Instancio la conexion SQL
                usuario.Connection = Wdcon_usuario;

                //Registro el Query SQL
                usuario.CommandText = "SELECT * FROM Vista_Horarios_Docentes WHERE (HRAFIN = @horafin) AND (HRADIA = @dia)";
                usuario.Parameters.AddWithValue("@horafin", hora);
                usuario.Parameters.AddWithValue("@dia", cortedia);

                //Abro la conexion
                Wdcon_usuario.Open();

                //Ejecuto la consulta
                usuarioDR = usuario.ExecuteReader();

                //Empiezo el ciclo
                while (usuarioDR.Read())
                {
                    if (usuarioDR["HRARES"].ToString() != "")
                    {
                        if (Validar_Docente(Convert.ToInt64(usuarioDR["HRARES"].ToString())) == true)
                        {
                            DateTime inicio1 = (DateTime)usuarioDR["HRAINI"];
                            DateTime fecha2 = inicio1.AddMinutes((-1) * Holgura_Academica());
                            string inicio = Funciones.ObtenerHora(fecha2);
                            Int64 docente = Convert.ToInt64(usuarioDR["HRARES"].ToString());
                            if (SalioCorrectamente(docente, inicio, cortedia) == true)
                            {
                                //Calculo las horas que dio clases
                                CalcularHoras(docente, inicio, cortedia);
                            }
                            else
                            {
                                //Denegar la persona
                                Insertar_Denegado(docente, DateTime.Now, Convert.ToDateTime(inicio), Convert.ToDateTime(cortedia));
                            }
                        }
                    }
                }
                //Cierro la conexion

                Wdcon_usuario.Close();
            }
        }
        .
        .
        .
      }

Hope you can help me to solve this, thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:05:12+00:00Added an answer on May 31, 2026 at 1:05 am

    I fixed it, it seems the error was because i had the same logname from another service name i had, i changed it and now it seems working (let´s say it starts)

    I used this from another blog to solve the error and find what was wrong

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    using System.Diagnostics;
    
    namespace SerivicioBIOHAcademico
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            static void Main()
            {
                try
                {
                    ServiceBase[] ServicesToRun;
                    ServicesToRun = new ServiceBase[] 
                    { 
                        new BIOHAcad() 
                    };
                    ServiceBase.Run(ServicesToRun);
                }
                catch(Exception ex)
                {
                    string SourceName = "WindowsService.ExceptionLog";
                    if (!EventLog.SourceExists(SourceName))
                    {
                        EventLog.CreateEventSource(SourceName, "Application");
                    }
    
                    EventLog eventLog = new EventLog();
                    eventLog.Source = SourceName;
                    string message = string.Format("Exception: {0} \n\nStack: {1}", ex.Message, ex.StackTrace);
                    eventLog.WriteEntry(message, EventLogEntryType.Error);
                }
            }
        }
    }
    

    It gave me the error i needed

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks for reading this. I am dynamically generating some data which includes a select
Thanks for reading this. I have markup similar to what is below. Using the
Thanks for reading this I thought I could use find(), but couldn't make it
Thanks for reading this. I would have thought it would be as simple as
Thanks to reading about error handling on StackOverflow , I discovered Mz-Tools. However, I
Thanks in Advance for reading and answer this question. I got button in asp
I'm reading about Rails fixtures in this guide (thanks, trevorturk). It appears you define
I've been reading this post on the android developer blog about the twitter client
this is some kind of long post, so I have to say thanks for
Hope this post will not be killed on the ground of NOT PROGRAMMING RELATED.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.