473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Logging into SQL Server from Windows Service

I have an Windows forms application written in VB.NET that uses a SQL Server
2000 back end database with Windows authentication. There is no problem
accessing the database from my application, or from an installed version of
the application on another machine. My problem is that I would like to
access the database overnight unattended to perform some maintenance tasks.
With my fairly limited knowledge of SQL Server and VB.NET, I thought that
the best way to do this would be using a windows service with a timer, so
that it could be running all the time while windows is running and the timer
could perform the maintenance at the correct time. I created a new Windows
Service project and added a reference to the same data access .dll that my
main application uses. The service installs and starts OK, and I can use the
methods in the external .dll, but whenever I try to access the database, I
get the error message 'Login failed for user 'DOMAIN2K\STAT28$'. The server,
running Windows 2000 Server, is DOMAIN2K, and my username is STAT28 which is
an Administrator on DOMAIN2K. My questions are 1) Is a windows service the
best way to do this? and 2) Why am I getting a login error using the same
data access functions that work fine in the main application? Thanks in
advance.

Andy Baker
Nov 21 '05 #1
4 3687
how have you setup your service to run? I think in order for you to do what
you want you have to install it using a domain user account that has the SQL
permissions you want.

--
--Eric Cathell, MCSA
"Andy Baker" <ab****@NOSPAMvanputer.com> wrote in message
news:43***********************@ptn-nntp-reader04.plus.net...
I have an Windows forms application written in VB.NET that uses a SQL
Server 2000 back end database with Windows authentication. There is no
problem accessing the database from my application, or from an installed
version of the application on another machine. My problem is that I would
like to access the database overnight unattended to perform some
maintenance tasks. With my fairly limited knowledge of SQL Server and
VB.NET, I thought that the best way to do this would be using a windows
service with a timer, so that it could be running all the time while
windows is running and the timer could perform the maintenance at the
correct time. I created a new Windows Service project and added a reference
to the same data access .dll that my main application uses. The service
installs and starts OK, and I can use the methods in the external .dll, but
whenever I try to access the database, I get the error message 'Login
failed for user 'DOMAIN2K\STAT28$'. The server, running Windows 2000
Server, is DOMAIN2K, and my username is STAT28 which is an Administrator on
DOMAIN2K. My questions are 1) Is a windows service the best way to do this?
and 2) Why am I getting a login error using the same data access functions
that work fine in the main application? Thanks in advance.

Andy Baker

Nov 21 '05 #2
By default, a Windows Service logs into the special local "SYSTEM"
account. This account does not have access to any network objects, SQL
or otherwise. You'll need to change the service startup parameters to
log into a domain account instead.

Nov 21 '05 #3
Thanks for the replies. I have created my service, then following the
instructions in Microsoft's Visual Basic.NET programmer's cookbook, I have
added an installer to the service project and then used InstallUtil to
install the service.Part of the code that is generated by the installer is

'
'ServiceProcessInstaller1
'
Me.ServiceProcessInstaller1.Account =
ServiceProcess.ServiceAccount.LocalSystem
Me.ServiceProcessInstaller1.Password = Nothing
Me.ServiceProcessInstaller1.Username = Nothing

'
'ServiceInstaller1
'
Me.ServiceInstaller1.ServiceName = "VPHousekeeping" 'Name of
maintenance service
Me.ServiceInstaller1.StartType =
ServiceProcess.ServiceStartMode.Automatic
'
'ProjectInstaller
'
Me.Installers.AddRange(New System.Configuration.Install.Installer()
{Me.ServiceProcessInstaller1, Me.ServiceInstaller1})
If I then change it to

Me.ServiceProcessInstaller1.Account =
ServiceProcess.ServiceAccount.NetworkService
Me.ServiceProcessInstaller1.Password = ""
Me.ServiceProcessInstaller1.Username = "STAT28"

I still get the logon error - also if I use
ServiceProcess.ServiceAccount.User. STAT28 is an administrator on the
domain, and there is no logon password (yet). I'm obviously missing
something, but I can't see what it is.

Regards,

Andy Baker

<za***@construction-imaging.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
By default, a Windows Service logs into the special local "SYSTEM"
account. This account does not have access to any network objects, SQL
or otherwise. You'll need to change the service startup parameters to
log into a domain account instead.

Nov 21 '05 #4
Found it - if I change to

Me.ServiceProcessInstaller1.Username = "DOMAIN2K\STAT28"

it works OK.

"Andy Baker" <ab****@NOSPAMvanputer.com> wrote in message
news:43***********************@ptn-nntp-reader04.plus.net...
Thanks for the replies. I have created my service, then following the
instructions in Microsoft's Visual Basic.NET programmer's cookbook, I have
added an installer to the service project and then used InstallUtil to
install the service.Part of the code that is generated by the installer is

'
'ServiceProcessInstaller1
'
Me.ServiceProcessInstaller1.Account =
ServiceProcess.ServiceAccount.LocalSystem
Me.ServiceProcessInstaller1.Password = Nothing
Me.ServiceProcessInstaller1.Username = Nothing

'
'ServiceInstaller1
'
Me.ServiceInstaller1.ServiceName = "VPHousekeeping" 'Name of
maintenance service
Me.ServiceInstaller1.StartType =
ServiceProcess.ServiceStartMode.Automatic
'
'ProjectInstaller
'
Me.Installers.AddRange(New System.Configuration.Install.Installer()
{Me.ServiceProcessInstaller1, Me.ServiceInstaller1})
If I then change it to

Me.ServiceProcessInstaller1.Account =
ServiceProcess.ServiceAccount.NetworkService
Me.ServiceProcessInstaller1.Password = ""
Me.ServiceProcessInstaller1.Username = "STAT28"

I still get the logon error - also if I use
ServiceProcess.ServiceAccount.User. STAT28 is an administrator on the
domain, and there is no logon password (yet). I'm obviously missing
something, but I can't see what it is.

Regards,

Andy Baker

<za***@construction-imaging.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
By default, a Windows Service logs into the special local "SYSTEM"
account. This account does not have access to any network objects, SQL
or otherwise. You'll need to change the service startup parameters to
log into a domain account instead.


Nov 21 '05 #5

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

Similar topics

0
by: Todd Bright | last post by:
Does anyone know of a reason that a Windows service written in C# would prevent the system from rebooting or logging off? The service starts another thread which displays a form (processing is...
0
by: Ollie Riches | last post by:
I have managed to get asycnhronous logging work for an asp.net application and I wanted some clarification on the method. Normally if the application is logging synchronously it has all the...
16
by: Einar Høst | last post by:
Hi, I'm getting into the Trace-functionality in .NET, using it to provide some much-needed logging across dlls in the project we're working on. However, being a newbie, I'm wondering if some...
1
by: Ron Bremmers | last post by:
Hello, I have a Windows Service which executes some code each 2 seconds. Every 2 seconds I want to log the result in a Windows Forms application. What is the best approach? I think it is...
9
by: Claudio Grondi | last post by:
I am aware, that it is maybe the wrong group to ask this question, but as I would like to know the history of past file operations from within a Python script I see a chance, that someone in this...
3
by: philwilks | last post by:
I have a dedicated server on which I run several ASP.Net 2.0 website. At the moment, each site has an Application_OnError subroutine that is defined in the site's Global.asax file. This writes the...
17
by: Cramer | last post by:
I plan to implement an exception logging feature in an ASP.NET Web application that writes encountered exceptions to disk. The exception data will be stored as XML. I am planning on having each...
1
by: nathan.alden | last post by:
I have a Windows application that must "log in" to a remote service. Once logged in, for all subsequent service calls the Windows application should somehow pass a "session context" in each message...
5
by: Daniel S | last post by:
Hi, I'm new here. I'm using the Logging Application Block with Enterprise Library 3.1. My program works correctly on my XP developer station, but on the 2003 Server, no new entries appear in...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.