Windows service and oledb

R

Roel Oost

Created a vb.net windows service which connect to a database by using OleDb.
Using a connectionstring pointing to a local sqlserver database everything
works fine, but when connecting to a database on another server the
connection.open method executes without errors but the connection stays
closed.
When using same code in a winform or webform app things goes as expected.
Is there some kind of restriction to windows services to use resources from
another server?

Roel
 
S

Steven Cheng[MSFT]

Hi Roel,

Welcome to MSDN newsgroup.
Regarding on the problem you mentioend, based on my experience, it is
likely a security issue. for connecting to the SQLSERVER, what's your
connection string? I think you're using windows authentiation so that the
application will use the process's current running account to access the
Remote sqlserver. Generally, for deskop applications(winform or console),
the application is running under the current logon user session. For
windows NT service, they're running under a non interactive logon session(
local service, NetworkService or LOCAL SYSTEM) as you specified in the
Service control manager. And when accessing to a remote resource(on remote
computer), local account can not be foward and recognized on remote
machine which may cause your application(service ) faile to establish the
connection. To verify this , you can start the SQL Profiler on the remote
machine which host the remote sqlserver and check the account that used
when try establishing the connection (failed). Also, please check in the
service control manager to see what's the account that configured to run
the servie.

BTW, for accessing SQLServer, why don't you use the .NET SqlServer managed
provider which is specifically optimized for SQLServer.

If there're anything unclear, please feel free to post here.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Roel Oost" <[email protected]>
| Subject: Windows service and oledb
| Date: Fri, 23 Sep 2005 09:04:25 +0200
| Lines: 12
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: 62.166.136.88
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.framework.adonet:36245
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Created a vb.net windows service which connect to a database by using
OleDb.
| Using a connectionstring pointing to a local sqlserver database everything
| works fine, but when connecting to a database on another server the
| connection.open method executes without errors but the connection stays
| closed.
| When using same code in a winform or webform app things goes as expected.
| Is there some kind of restriction to windows services to use resources
from
| another server?
|
| Roel
|
|
|
 
R

Roel Oost

I don't use windows authentication to connect to the server. The connection
string is something like
"Provider=SQLOLEDB;Data Source=servername;Initial
Catalog=dbname;uid=username;pwd=password", so guess that should be no
problem. Same code in a winform or webform app works fine, but only from a
windows service the connection.open method behaves in described strange way
(con.Open executes fine but results in a closed connection)
Yes, I also wondered about using OleDb instead of SQLClient. It was an
historical choice, using OleDb should be easier to use in the case the
customer chooses another database to use. But that risk is almost nihil at
the moment.
I've evaluated the behavior of the SQLClient provider in this situation and
guess what, it works fine....
Still wondering about why OleDb doesn't in this case. I've configurated the
winservice using the LocalSystem account, a local user account and a domain
user account, to see if it has something to do with access to the database
server machine (before connecting to the machine), but all same result...
Hope to find an answer because for other connectiontypes we stille depends
on OleDb.

Roel

Steven Cheng said:
Hi Roel,

Welcome to MSDN newsgroup.
Regarding on the problem you mentioend, based on my experience, it is
likely a security issue. for connecting to the SQLSERVER, what's your
connection string? I think you're using windows authentiation so that the
application will use the process's current running account to access the
Remote sqlserver. Generally, for deskop applications(winform or console),
the application is running under the current logon user session. For
windows NT service, they're running under a non interactive logon session(
local service, NetworkService or LOCAL SYSTEM) as you specified in the
Service control manager. And when accessing to a remote resource(on
remote
 
W

William \(Bill\) Vaughn

Make sure that you're trapping all exceptions and the target server is setup
to support mixed mode security--it defaults to SSPI only. I would avoid use
of OleDb when connecting to SQL Server. It's slower, and is COM-dependant.
SqlClient is THE interface to use. Just because you're using OleDb, you
won't be able to port your application over simply by changing provider
names. It's never that simple.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
S

Steven Cheng[MSFT]

Thanks for your response Roel,

So from your further description on the problem, it seems the cause is not
quite related to the application(service)'s security context. Also, you
found it works well when you swtich to .NET's SQLClient managed provider.
Since you mentioned, that the Conn.Open executed fine by the returned
connection is closed, what did you get if you using the sql profiler to
trace at the SQLServer's servermachine? Currently I haven't found any
non-issue in internal db on using OLEDB provider for SQLServer in windows
NT service. Have you tried deploying the same service on the other server
to see whether you'll get the same problem?

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)








--------------------
| From: "Roel Oost" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Windows service and oledb
| Date: Fri, 23 Sep 2005 13:06:55 +0200
| Lines: 39
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: 62.166.136.88
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.framework.adonet:36253
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| I don't use windows authentication to connect to the server. The
connection
| string is something like
| "Provider=SQLOLEDB;Data Source=servername;Initial
| Catalog=dbname;uid=username;pwd=password", so guess that should be no
| problem. Same code in a winform or webform app works fine, but only from a
| windows service the connection.open method behaves in described strange
way
| (con.Open executes fine but results in a closed connection)
| Yes, I also wondered about using OleDb instead of SQLClient. It was an
| historical choice, using OleDb should be easier to use in the case the
| customer chooses another database to use. But that risk is almost nihil at
| the moment.
| I've evaluated the behavior of the SQLClient provider in this situation
and
| guess what, it works fine....
| Still wondering about why OleDb doesn't in this case. I've configurated
the
| winservice using the LocalSystem account, a local user account and a
domain
| user account, to see if it has something to do with access to the database
| server machine (before connecting to the machine), but all same result...
| Hope to find an answer because for other connectiontypes we stille depends
| on OleDb.
|
| Roel
|
| | > Hi Roel,
| >
| > Welcome to MSDN newsgroup.
| > Regarding on the problem you mentioend, based on my experience, it is
| > likely a security issue. for connecting to the SQLSERVER, what's your
| > connection string? I think you're using windows authentiation so that
the
| > application will use the process's current running account to access the
| > Remote sqlserver. Generally, for deskop applications(winform or
console),
| > the application is running under the current logon user session. For
| > windows NT service, they're running under a non interactive logon
session(
| > local service, NetworkService or LOCAL SYSTEM) as you specified in the
| > Service control manager. And when accessing to a remote resource(on
| remote
|
|
|
 
R

Roel Oost

Hi Steven,
There I now have a working and stabil solution with SQLOLEDB the problem
with OLEDB has no priority at the moment.
The problem is probably related to SQL Server and OLEDB (evt. in combination
with our server environment) only. I do facilitate an OLEDB connection to
Analysis Server also and that connection works fine. When the problem ever
became actual again, I will remind your hints to discover the source of the
problem.
Thanks for now,

Roel Oost
MMGuide B.V., The Netherlands
 
S

Steven Cheng[MSFT]

Thanks for your followup Roel.

Sure, please feel free to post here when you need any further assistance.

Good luck!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Roel Oost" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Windows service and oledb
| Date: Mon, 26 Sep 2005 09:55:19 +0200
| Lines: 119
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: 62.166.136.88
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.framework.adonet:36368
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Hi Steven,
| There I now have a working and stabil solution with SQLOLEDB the problem
| with OLEDB has no priority at the moment.
| The problem is probably related to SQL Server and OLEDB (evt. in
combination
| with our server environment) only. I do facilitate an OLEDB connection to
| Analysis Server also and that connection works fine. When the problem ever
| became actual again, I will remind your hints to discover the source of
the
| problem.
| Thanks for now,
|
| Roel Oost
| MMGuide B.V., The Netherlands
|
| | > Thanks for your response Roel,
| >
| > So from your further description on the problem, it seems the cause is
not
| > quite related to the application(service)'s security context. Also, you
| > found it works well when you swtich to .NET's SQLClient managed
provider.
| > Since you mentioned, that the Conn.Open executed fine by the returned
| > connection is closed, what did you get if you using the sql profiler to
| > trace at the SQLServer's servermachine? Currently I haven't found any
| > non-issue in internal db on using OLEDB provider for SQLServer in
windows
| > NT service. Have you tried deploying the same service on the other
server
| > to see whether you'll get the same problem?
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| >
| >
| >
| >
| > --------------------
| > | From: "Roel Oost" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > | Subject: Re: Windows service and oledb
| > | Date: Fri, 23 Sep 2005 13:06:55 +0200
| > | Lines: 39
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.adonet
| > | NNTP-Posting-Host: 62.166.136.88
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| microsoft.public.dotnet.framework.adonet:36253
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
| > |
| > | I don't use windows authentication to connect to the server. The
| > connection
| > | string is something like
| > | "Provider=SQLOLEDB;Data Source=servername;Initial
| > | Catalog=dbname;uid=username;pwd=password", so guess that should be no
| > | problem. Same code in a winform or webform app works fine, but only
from
| a
| > | windows service the connection.open method behaves in described
strange
| > way
| > | (con.Open executes fine but results in a closed connection)
| > | Yes, I also wondered about using OleDb instead of SQLClient. It was an
| > | historical choice, using OleDb should be easier to use in the case the
| > | customer chooses another database to use. But that risk is almost
nihil
| at
| > | the moment.
| > | I've evaluated the behavior of the SQLClient provider in this
situation
| > and
| > | guess what, it works fine....
| > | Still wondering about why OleDb doesn't in this case. I've
configurated
| > the
| > | winservice using the LocalSystem account, a local user account and a
| > domain
| > | user account, to see if it has something to do with access to the
| database
| > | server machine (before connecting to the machine), but all same
| result...
| > | Hope to find an answer because for other connectiontypes we stille
| depends
| > | on OleDb.
| > |
| > | Roel
| > |
| > | | > | > Hi Roel,
| > | >
| > | > Welcome to MSDN newsgroup.
| > | > Regarding on the problem you mentioend, based on my experience, it
is
| > | > likely a security issue. for connecting to the SQLSERVER, what's
your
| > | > connection string? I think you're using windows authentiation so
that
| > the
| > | > application will use the process's current running account to access
| the
| > | > Remote sqlserver. Generally, for deskop applications(winform or
| > console),
| > | > the application is running under the current logon user session. For
| > | > windows NT service, they're running under a non interactive logon
| > session(
| > | > local service, NetworkService or LOCAL SYSTEM) as you specified in
the
| > | > Service control manager. And when accessing to a remote resource(on
| > | remote
| > |
| > |
| > |
| >
|
|
|
 
R

Roel Oost

Hi Steven,
Strang things happened today, it was to early to party.... Found out last
week SQLOLEDB was working fine for us. But today when connecting a strange
error occures on connection.open

Exception message:
SQLDumpExceptionHandler. Process 66 generated fatal exception c0000005
EXCEPTION_ACCESS_VIOLATION. SQL is terminating this process...

When looking in the eventviewer of the server (why didn't I do that
earlier....) the log was full of this errors also for the moments I've used
OLEDB to connect. So at that time SQLServer was in a errorstate but OLEDB
didn't trap that error.
Maybe you can tell me something about this error (and how to fix this).
I've found one KB article about it
(http://support.microsoft.com/?kbid=892451). BUT there the problem is
related to RIGHT OUTER JOINS in some queries. At this time I'm just trying
to open the connection....
Help...

Roel

b.t.w. we're currently running on SQL Server sp3a
 
R

Roel Oost

b.t.w. we're currently running on SQL Server sp3a
At least I expected it was, but better looking says that this particular
server works with no servicepack at all ;-)
Upgraded the servicepacklevel.... problem solved....

Roel
 
S

Steven Cheng[MSFT]

Hi Roel,

So sometimes the problem always be much simpler than we've ever expected
:). Also, leaving a server with unpatched SQLServer available on network
is really dangerous, maybe your IT guys need to take more care of this.
Anyway, glad that you've figured out the problem.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Roel Oost" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Windows service and oledb
| Date: Mon, 26 Sep 2005 17:28:30 +0200
| Lines: 48
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: 62.166.136.88
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.framework.adonet:36405
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| > b.t.w. we're currently running on SQL Server sp3a
| At least I expected it was, but better looking says that this particular
| server works with no servicepack at all ;-)
| Upgraded the servicepacklevel.... problem solved....
|
| Roel
|
| | > Hi Steven,
| > Strang things happened today, it was to early to party.... Found out
last
| > week SQLOLEDB was working fine for us. But today when connecting a
strange
| > error occures on connection.open
| >
| > Exception message:
| > SQLDumpExceptionHandler. Process 66 generated fatal exception c0000005
| > EXCEPTION_ACCESS_VIOLATION. SQL is terminating this process...
| >
| > When looking in the eventviewer of the server (why didn't I do that
| > earlier....) the log was full of this errors also for the moments I've
| used
| > OLEDB to connect. So at that time SQLServer was in a errorstate but
OLEDB
| > didn't trap that error.
| > Maybe you can tell me something about this error (and how to fix this).
| > I've found one KB article about it
| > (http://support.microsoft.com/?kbid=892451). BUT there the problem is
| > related to RIGHT OUTER JOINS in some queries. At this time I'm just
trying
| > to open the connection....
| > Help...
| >
| > Roel
| >
| > b.t.w. we're currently running on SQL Server sp3a
| >
| >
| > | > > Thanks for your followup Roel.
| > >
| > > Sure, please feel free to post here when you need any further
| assistance.
| > >
| > > Good luck!
| > >
| >
| >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top