Re: Connecting to SQL from a Windows Service



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


.



Relevant Pages

  • Re: login 101..
    ... On Windows 2003, SQL Server 2005 can enforce the Windows password complexity ... Windows authentication - SQL Server uses a special protocol to ask ... user is in the list of allowed logins, ...
    (microsoft.public.sqlserver.security)
  • RE: How to create a trusted connection
    ... You need to grant access for the Windows login by referring to the books ... is set to use Windows authentication to be able to do trusted connection. ... There are two modes of authentication in SQL Server: ...
    (microsoft.public.sqlserver.security)
  • Re: Windows XP Service Pack 2 SAS Application Error
    ... There is nothing else unusual in the event log at that time. ... We are having some trouble on Windows XP Service Pack 2. ... process of updating all our computers from Windows XP Service Pack 1 to ... When certain users attempt to login, they receive an error after they ...
    (microsoft.public.windowsxp.security_admin)
  • RE: How to create a trusted connection
    ... What do you mean by "creating a Windows login"? ... To login SQL Server 2000 using trusted connection, grant the Windows ... Group" in SQL Server Books Online to get the concept, ...
    (microsoft.public.sqlserver.security)
  • Re: Trusted SQL Server connection (SQL 2005)
    ... To be able to login to SQL Server using a Windows account, then a login must be created in SQL Server Security\Login for that account or for a Windows group which consists that Windows account. ... Create login for the Windows group who you want them to be able to login to your SQL Server and assign them necessary permissions for your database objects or whatever. ...
    (microsoft.public.sqlserver.security)