Re: Connecting to SQL from a Windows Service
- From: "Rick Byham, \(MSFT\)" <rickbyh@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 20 Mar 2008 14:56:24 -0700
Sorry, I don't think I can help. Since it only fails when you boot, I'm going to guess that Windows hasn't fully started something. You could go fishing through the various other services and make your app dependant upon them. Things like Net Logon. There is probably some way to debug this, but that's deeper Windows knowledge than I can dredge up right now.
--
Rick Byham (MSFT)
This posting is provided "AS IS" with no warranties, and confers no rights.
"RML" <RML@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:58D14A35-2F87-4945-9F09-457EE47EAB1F@xxxxxxxxxxxxxxxx
Hi Rick, I ran the sql script and all looks fine, the Login hasaccess and
points to my DB. I looked into the Event Log and found that when my service
starts, it logsin (connects) twice. The 1st succeeds, the 2nd fails and SQL
does not open the DB. This situation occurs only from bootup.
If I start the service manually, the Event Log shows:
1. 1st Login succeeds.
2. SQL opens my DB.
3. 2ne Login succeeds.
I next added a Sleep for 10sec at the top of my OnStart() event of my
service. Now when I bbot and the service starts, all works fine. The Event
Log sequences like above.
I do have my service dependant on MSSQL$SQLEXPRESS, and I do see in the
Event Log that SQL Express is "Ready to accept client connections..." before
my service attempts to Login. What am I missing? Do I need to make my
service dependant on something else?
I did save off the Event Logs if you are interested.
RML
"Rick Byham, (MSFT)" wrote:
When you are connected to SQL Server as "Windows (XP Pro) as an Admin" and
you run the query:
USE master
GO
SELECT * FROM syslogins
WHERE name = 'NT AUTHORITY\SYSTEM'
GO
Does it return a row for that login?
And most of the values should look like your login: denylogin = 0, hasaccess
= 1, dbname is probably master or your desired database.
And after login, does the 'NT AUTHORITY\SYSTEM' has access to the correct
database as a user?
Also, You can try turning on login auditing in SQL Server and then check the
SQL Server error log. Maybe you will see more info about the login attempt.
--
Rick Byham (MSFT)
This posting is provided "AS IS" with no warranties, and confers no rights.
"RML" <RML@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E21B3350-9477-4DCE-8E64-3690FFB2BAD3@xxxxxxxxxxxxxxxx
> Hi all, I have written a Windows Service that attempts to connect to an
> SQL
> 2005 Express Database when started. The login always fails. The login
> uses
> Windows Authentification (NT AUTHORITY/SYSTEM user).
>
> I also tried connecting using the "sa" SQL Server login, and it still
> fails.
>
> If I log into Windows (XP Pro) as an Admin, and manually start the
> service,
> it connect Ok.
>
> I thought that maybe the SQL Server service "MSSQL$SQLEXPRESS" may not > be
> started yet when my service attempts to connect, but the Evetn Log show > it
> is
> started before my service starts. Also, my service is Dependant on
> MSSQL$SQLEXPRESS.
>
> Can anyone point me in the right direction.
>
> RML
.
- References:
- Re: Connecting to SQL from a Windows Service
- From: Rick Byham, \(MSFT\)
- Re: Connecting to SQL from a Windows Service
- From: RML
- Re: Connecting to SQL from a Windows Service
- Prev by Date: Re: Connecting to SQL from a Windows Service
- Next by Date: Re: I cannot Create an ODBC source for SQL server 2005
- Previous by thread: Re: Connecting to SQL from a Windows Service
- Next by thread: Re: I cannot Create an ODBC source for SQL server 2005
- Index(es):
Relevant Pages
|