| [solved]My Windows Service Won't Start? | |
|
Author | Message |
---|
HoxBox Member
Posts : 3 Join date : 2011-07-01
| Subject: [solved]My Windows Service Won't Start? Sat 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 |
|
| |
Ween Member
Posts : 1 Join date : 2011-07-01
| Subject: Re: [solved]My Windows Service Won't Start? Sat 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? |
|
| |
HoxBox Member
Posts : 3 Join date : 2011-07-01
| Subject: Re: [solved]My Windows Service Won't Start? Sat 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? |
|
| |
Sharp Member
Posts : 3 Join date : 2011-05-20
| Subject: Re: [solved]My Windows Service Won't Start? Sat Dec 10, 2011 5:14 am | |
| Do you really have a DataGrid in your Windows Service? |
|
| |
Iconic Member
Posts : 4 Join date : 2011-06-17
| Subject: Re: [solved]My Windows Service Won't Start? Sat 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. |
|
| |
Sharp Member
Posts : 3 Join date : 2011-05-20
| Subject: Re: [solved]My Windows Service Won't Start? Sat 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. |
|
| |
Zora Member
Posts : 12 Join date : 2011-06-24
| Subject: Re: [solved]My Windows Service Won't Start? Sat 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 |
|
| |
Sponsored content
| Subject: Re: [solved]My Windows Service Won't Start? | |
| |
|
| |
| [solved]My Windows Service Won't Start? | |
|