473,722 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\STAT2 8$'. 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 3704
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****@NOSPAMv anputer.com> wrote in message
news:43******** *************** @ptn-nntp-reader04.plus.n et...
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\STAT2 8$'. 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

'
'ServiceProcess Installer1
'
Me.ServiceProce ssInstaller1.Ac count =
ServiceProcess. ServiceAccount. LocalSystem
Me.ServiceProce ssInstaller1.Pa ssword = Nothing
Me.ServiceProce ssInstaller1.Us ername = Nothing

'
'ServiceInstall er1
'
Me.ServiceInsta ller1.ServiceNa me = "VPHousekeeping " 'Name of
maintenance service
Me.ServiceInsta ller1.StartType =
ServiceProcess. ServiceStartMod e.Automatic
'
'ProjectInstall er
'
Me.Installers.A ddRange(New System.Configur ation.Install.I nstaller()
{Me.ServiceProc essInstaller1, Me.ServiceInsta ller1})
If I then change it to

Me.ServiceProce ssInstaller1.Ac count =
ServiceProcess. ServiceAccount. NetworkService
Me.ServiceProce ssInstaller1.Pa ssword = ""
Me.ServiceProce ssInstaller1.Us ername = "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***@construc tion-imaging.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.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.ServiceProce ssInstaller1.Us ername = "DOMAIN2K\STAT2 8"

it works OK.

"Andy Baker" <ab****@NOSPAMv anputer.com> wrote in message
news:43******** *************** @ptn-nntp-reader04.plus.n et...
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

'
'ServiceProcess Installer1
'
Me.ServiceProce ssInstaller1.Ac count =
ServiceProcess. ServiceAccount. LocalSystem
Me.ServiceProce ssInstaller1.Pa ssword = Nothing
Me.ServiceProce ssInstaller1.Us ername = Nothing

'
'ServiceInstall er1
'
Me.ServiceInsta ller1.ServiceNa me = "VPHousekeeping " 'Name of
maintenance service
Me.ServiceInsta ller1.StartType =
ServiceProcess. ServiceStartMod e.Automatic
'
'ProjectInstall er
'
Me.Installers.A ddRange(New System.Configur ation.Install.I nstaller()
{Me.ServiceProc essInstaller1, Me.ServiceInsta ller1})
If I then change it to

Me.ServiceProce ssInstaller1.Ac count =
ServiceProcess. ServiceAccount. NetworkService
Me.ServiceProce ssInstaller1.Pa ssword = ""
Me.ServiceProce ssInstaller1.Us ername = "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***@construc tion-imaging.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.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
1180
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 done in the form so as to not interfere with the service's thread execution). Stopping the service is the only way I've found to yield and let the system reboot or log off. I tried using the SystemEvents.SessionEnding event and that works great for...
0
1545
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 settings for the logging application block in the app.config for the application. But if you want to use asynchronous logging you have to specify asynchronous logging for all logging types in the app.config of the application and then define the...
16
2170
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 more experienced loggers can provide me with some ideas as to how to log in a simple yet flexible manner. For instance, I'd like the code to be as uncluttered as possible by Trace statements. As an example of basic logging functionality, I've come...
1
1533
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 .NET remoting, but when the "client" application is not started, no logging has to be done. So the service has to know if there is a client application to log to. How can I do
9
2236
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 group was into it already and is so kind to share here his experience. I have put already much efforts into this subject googling around, but up to now in vain. Best option I encountered yet is usage of the Greyware 'System Change Log' service...
3
1122
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 error to a log file, as well as emailing me with an alert. Is there a better way to do this? Ideally, I'd just have one thing set up that would pick up errors from any of my websites. I was thinking that there might be a way to use the Windows...
17
2748
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 exception written to its own XML file. I plan to NOT append exceptions to a single XML file because I don't want for the exception logging component to have to deal with contention for access to the file. This is possible when, for example,...
1
2423
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 to the service, which will then be compared to session information stored in SQL Server. However, for each service call a new client proxy is created, i.e. I'm not reusing the same proxy over and over. Essentially, I need to emulate what...
5
1588
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 the Application log after calls to Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(object message), but those calls aren't throwing exceptions, either.
0
8863
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
8739
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
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
9157
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
8052
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...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.