473,698 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Service that Reads/Writes Files/SQL Server

Hi,

I want to create a Service that Reads and Write Files, and Insert and Select
Data from a Sql Server Database.

I did a little test with a small Service that I wanted to write something to
a File when it starts and stops. I did it like this:
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Dim swFile As StreamWriter =
File.AppendText ("c:\ServicePie terP2.log")
swFile.WriteLin e("blabla")
End Sub

Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your
service.
Dim swFile As StreamWriter =
File.AppendText ("c:\ServicePie terP2.log")
swFile.WriteLin e("blabla2")
End Sub
I'm able to create and install the service, but when I Start it, the File
"c:\ServicePiet erP2.log" is created, but nothing is written in it!! And when
I try to stop the service I got an error (time-out).

Can anybody help me with this? Is it possible to write to a file with a
service? does anybody knows a good site about making Services in VB.NET that
reads/writes filesand Sql Server?

Thanks a lot in advance,

Pieter
Nov 20 '05 #1
1 1188
Hello Pieter.

Should not be any problem.
As a service, you can enter credentials for the service, so that permissions
allow you to create the files, as has been done in your test.
If your service runs as an administrator, as you yourself probably are on
you own computer, there is no real difference in how you can access files
and object libraries between a service and a windows application.

From the code you submitted though, it seems that the problem lies in the
StreamWriter code.
A stream is not persisted to disk until you flush it.
Also it is good practice to close the stream before exiting the function.

The code should look like this:.

Dim swFile As StreamWriter = File.AppendText ("c:\ServicePie terP2.log")

swFile.WriteLin e("blabla")
swFile.Flush()
swFile.Close()
swFile = Nothing

From MSDN:
You must call Close to ensure that all data is correctly written out to the
underlying stream. Following a call to Close, any operations on the
StreamWriter might raise exceptions.

Flushing the stream will not flush its underlying encoder unless you
explicitly call Flush or Close. Setting AutoFlush to true means that data
will be flushed from the buffer to the stream, but the encoder state will
not be flushed. This allows the encoder to keep its state (partial
characters) so that it can encode the next block of characters correctly.
This scenario affects UTF8 and UTF7 where certain characters can only be
encoded after the encoder receives the adjacent character or characters.
// Henrik


"DraguVaso" <pi**********@h otmail.com> wrote in message
news:eg******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I want to create a Service that Reads and Write Files, and Insert and Select Data from a Sql Server Database.

I did a little test with a small Service that I wanted to write something to a File when it starts and stops. I did it like this:
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things ' in motion so your service can do its work.
Dim swFile As StreamWriter =
File.AppendText ("c:\ServicePie terP2.log")
swFile.WriteLin e("blabla")
End Sub

Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your
service.
Dim swFile As StreamWriter =
File.AppendText ("c:\ServicePie terP2.log")
swFile.WriteLin e("blabla2")
End Sub
I'm able to create and install the service, but when I Start it, the File
"c:\ServicePiet erP2.log" is created, but nothing is written in it!! And when I try to stop the service I got an error (time-out).

Can anybody help me with this? Is it possible to write to a file with a
service? does anybody knows a good site about making Services in VB.NET that reads/writes filesand Sql Server?

Thanks a lot in advance,

Pieter

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2491
by: murphy | last post by:
I'm programming a site that displays info from AWS Commerce Service 4.0. At each change of the asp.net application the first load of a page that uses the web service takes 30 seconds. Subsequent calls are snappy. From what I've learned this overhead is for processing the wsdl file (which has of course not changed). The file is large, 2200 lines. Is there a way to use this file locally on the web server or cache the result of the...
4
2056
by: Claire | last post by:
Hi, I know this isn't strictly C# language related, but my service IS written in c# and I checked out the list of microsoft newsgroups for win2000 and couldn't really see one that applies. I'm trying to test my service on a remote win2000 server machine, accessing the machine as user "administrator" on remote desktop. Im just at the install stage and using the installutil.exe to register the service on the server. The install appears to...
3
6619
by: JL | last post by:
I have a VB.NET desktop program that reads/writes data to a server using a Java-based Web Service. This web service, in identical formats, is located on several servers with each server being a different customer and different data content. To connect with the Java Web Service, I downloaded the WSDL file and used wsdl.exe to create a .vb class file. In my program, I simply call the functions of the class to communicate with the server. ...
3
2608
by: Chris Dunaway | last post by:
I am writing a Windows Service that reads and processes files on a set schedule. I want to create a second app that can monitor the Windows service. The Windows service will write trace messages at certain points while executing. The monitoring app I want to write will be very simple, just picking up these traces and displaying them to show progress of the service. My question is what is the best method of communication between the...
2
2455
by: Trevor | last post by:
Argh! This problem is driving me nuts! Can you help? In November of 2003, I installed a web service on Windows Server 2003 built in VB.NET for v1.1.4322 of the framework. It contains a timer (System.Timers.Timer) which has an interval of 24 hours. Actually, it reads a time like 2AM out of the config file, and calculates the time between the start of the service to 2AM, and sets the timer. When the timer expires, it re-reads the...
3
1407
by: Terry Olsen | last post by:
I have a windows service that has been running fine for almost 6 months. Last week, it just stopped working. It is still in the task list and still shows "started" in the service manager. There are no exceptions thrown, it just seems to have fell asleep. The service runs in a loop that checks about 80 servers on a daily basis to see what the status of the previous nights backup job is. It downloads the zipped log files from each...
0
889
by: mattmcgregor | last post by:
I'm using Visual Studio 2008 and have got a project with the following: Web Service (on a server): 1 web method that returns an xml list of files stored on the server. It references Component A to return that list. Win Forms App (laptop): Has a local file list that I want to compare to the server list. The win app references Component A to read the local file list and call the web service to read the server list and compare them. ...
5
3527
by: Yash | last post by:
Hi, I am using SQL 2000 SP4. I have compared 2 scenarios: Scenario 1: insert into #bacs_report SELECT ..... WHERE <conditions>
0
8680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9030
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7738
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.