Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 [solved]My Windows Service Won't Start?

View previous topic View next topic Go down 
AuthorMessage
HoxBox
Member
Member
HoxBox

Posts : 3
Join date : 2011-07-01

[solved]My Windows Service Won't Start? Empty
PostSubject: [solved]My Windows Service Won't Start?   [solved]My Windows Service Won't Start? EmptySat Dec 10, 2011 5:12 am

Here's my code. Is it blindingly obvious why my service won't run?


Code:

Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Configuration.Configuration
Imports System.Windows.Forms

Public Class Service1

    Protected Overrides Sub OnStart(ByVal args() As String)

        Dim myConnectionString As String = "" 'Declare and initialize it.
        Dim myConnection As SqlConnection = Nothing

        'check for the connectionstring
        If ConfigurationManager.ConnectionStrings("IrisLookupString") Is Nothing Then
            'MessageBox.Show("The Connection String could not be located.")
            'Do what you need to do when the connection string isn't found...
        Else
            myConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("IrisLookupString").ConnectionString)
        End If

        myConnection.Open()

        Dim da As New SqlDataAdapter("select ClientID, ClientName, InternalID from Iris.Practice.IbvClient WHERE ClientID NOT LIKE 'Z%'", myConnection)
        Dim ds As New DataSet
        da.Fill(ds, "Iris.Practice.IbvClient")
        DG.DataSource = ds.Tables("iris.practice.ibvclient")

        'Declaration of Variables

        Dim gridData(DG.Rows.Count - 1) As String
        For Each r As DataGridViewRow In DG.Rows
            If r.IsNewRow Then Exit For
            Dim cellValues(DG.Rows(r.Index).Cells.Count - 1) As String
            For Each c As DataGridViewCell In DG.Rows(r.Index).Cells
                cellValues(c.ColumnIndex) = c.Value.ToString
            Next
            gridData(r.Index) = String.Join(",", cellValues)
        Next
        Dim lines = From line In gridData _
                    Where line <> Nothing _
                    Select line

        Dim MyPath As String = (ConfigurationManager.AppSettings("OutputFilePath")) & "IrisClientList.csv"

        IO.File.WriteAllLines(MyPath, lines.ToArray)
        'Process.Start(MyPath)
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
    End Sub

End Class


Last edited by HoxBox on Sat Dec 10, 2011 5:17 am; edited 1 time in total
Back to top Go down
Ween
Member
Member
Ween

Posts : 1
Join date : 2011-07-01

[solved]My Windows Service Won't Start? Empty
PostSubject: Re: [solved]My Windows Service Won't Start?   [solved]My Windows Service Won't Start? EmptySat Dec 10, 2011 5:13 am

Removed original post.

Your code is all over the place, not only that but you haven't given enough information as to what exactly isn't working.

Are there errors?
Does it build?
What doesn't it do?
What are you meaning for it to do?
Back to top Go down
HoxBox
Member
Member
HoxBox

Posts : 3
Join date : 2011-07-01

[solved]My Windows Service Won't Start? Empty
PostSubject: Re: [solved]My Windows Service Won't Start?   [solved]My Windows Service Won't Start? EmptySat Dec 10, 2011 5:13 am

Many thanksd for the reply. Please excuse the code all over etc. Effectively this is the 2nd small utility I am doing with vb.net to get some exposure to it.

The code works fine in a windows form applicaiton and performs as expected. When using as a windows service the programme builds and service installs.

The issue is apparant when trying to start the service. Service control gets so far and returns error 1053 the service did not respond in a timely manner.

I think, it could be that the code is referring to a datadrid view, works fine in a forms app but I think is the issue in the service app.

i am thinking that that portion of the code needs a sqlcommand approach?
Back to top Go down
Sharp
Member
Member
Sharp

Posts : 3
Join date : 2011-05-20

[solved]My Windows Service Won't Start? Empty
PostSubject: Re: [solved]My Windows Service Won't Start?   [solved]My Windows Service Won't Start? EmptySat Dec 10, 2011 5:14 am

Do you really have a DataGrid in your Windows Service?
Back to top Go down
Iconic
Member
Member
Iconic

Posts : 4
Join date : 2011-06-17

[solved]My Windows Service Won't Start? Empty
PostSubject: Re: [solved]My Windows Service Won't Start?   [solved]My Windows Service Won't Start? EmptySat Dec 10, 2011 5:14 am

You've got no error handling to help you out. I would highly suggest adding it. Also, is your service running under a system account? If so you may be having problems connection to your database.
Back to top Go down
Sharp
Member
Member
Sharp

Posts : 3
Join date : 2011-05-20

[solved]My Windows Service Won't Start? Empty
PostSubject: Re: [solved]My Windows Service Won't Start?   [solved]My Windows Service Won't Start? EmptySat Dec 10, 2011 5:15 am

As Iconic said you most likely get an exception somewhere in your code. Since you're using a DataGrid, for some reason, I assumed you allowed your Service to interact with the desktop, if not you should use the LocalSystem account to ensure that you can access your database, that account has elevated privileges.
Back to top Go down
Zora
Member
Member
Zora

Posts : 12
Join date : 2011-06-24

[solved]My Windows Service Won't Start? Empty
PostSubject: Re: [solved]My Windows Service Won't Start?   [solved]My Windows Service Won't Start? EmptySat Dec 10, 2011 5:17 am

HoxBox wrote:

Here's my code. Is it blindingly obvious why my service won't run?


Code:

Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Configuration.Configuration
Imports System.Windows.Forms

Public Class Service1

    Protected Overrides Sub OnStart(ByVal args() As String)

        Dim myConnectionString As String = "" 'Declare and initialize it.
        Dim myConnection As SqlConnection = Nothing

        'check for the connectionstring
        If ConfigurationManager.ConnectionStrings("IrisLookupString") Is Nothing Then
            'MessageBox.Show("The Connection String could not be located.")
            'Do what you need to do when the connection string isn't found...
        Else
            myConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("IrisLookupString").ConnectionString)
        End If

        myConnection.Open()

        Dim da As New SqlDataAdapter("select ClientID, ClientName, InternalID from Iris.Practice.IbvClient WHERE ClientID NOT LIKE 'Z%'", myConnection)
        Dim ds As New DataSet
        da.Fill(ds, "Iris.Practice.IbvClient")
        DG.DataSource = ds.Tables("iris.practice.ibvclient")

        'Declaration of Variables

        Dim gridData(DG.Rows.Count - 1) As String
        For Each r As DataGridViewRow In DG.Rows
            If r.IsNewRow Then Exit For
            Dim cellValues(DG.Rows(r.Index).Cells.Count - 1) As String
            For Each c As DataGridViewCell In DG.Rows(r.Index).Cells
                cellValues(c.ColumnIndex) = c.Value.ToString
            Next
            gridData(r.Index) = String.Join(",", cellValues)
        Next
        Dim lines = From line In gridData _
                    Where line <> Nothing _
                    Select line

        Dim MyPath As String = (ConfigurationManager.AppSettings("OutputFilePath")) & "IrisClientList.csv"

        IO.File.WriteAllLines(MyPath, lines.ToArray)
        'Process.Start(MyPath)
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
    End Sub

End Class

Debug the service using


Add this code in start event
Code:

Protected Overrides Sub OnStart(ByVal args() As String)
 System.Diagnostics.Debugger.Launch

and select the visual studio ide and debug the code

Back to top Go down
Sponsored content




[solved]My Windows Service Won't Start? Empty
PostSubject: Re: [solved]My Windows Service Won't Start?   [solved]My Windows Service Won't Start? Empty

Back to top Go down
 

[solved]My Windows Service Won't Start?

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» [solved]Creating .txt file then writing to it.
» Where to start
» Where should i start?
» Quick Start Guide?
» when i start up my pc monitor, it becomes only black n gray?

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: [solved]My Windows Service Won't Start? Edit-trash Useless :: Trash-