views:

325

answers:

3

We are running part of our app as a windows service and it needs to b able to access DSNs in order to import through ODBC. However there seem to be a lot of restrictions found through trial and error on what DSNs it can access. For example it seems that it cannot 1. access a system DSN unless the account that is running the service has admin privileges. (I get an Access Denied error, when trying to connect) 2. access a user DSN that was created by a different user (this one is understandable). 3. access a file DSN across the network

I've read that the purpose of a file DSN is to allow other computers to use it to connect, however i can't seem to make that work.

So does any know, or know where i can find out what all the rules and restrictions on accessing a DSN are when using a windows service. thanks

+1  A: 

I think you've already discovered the three main rules yourself. :-)

Except that you probably don't need admin privileges for your service account. IANANA (I am not a network administrator), but your service account probably just needs read access to one of the ODBC files or directories.

MusiGenesis
+1  A: 

This is somewhere between your #1 and #2: sometimes correct file permissions are also necessary. I once had troubles on a Vista machine connecting to a DB2 DSN because, for whatever reason (maybe to write out temp files; although I don't know why it would do such a thing in this location instead of a user-specific one), the driver needed write access to the directory where IBM had installed the client binaries and libs, which had been done by an Administrator and was in the root of the C drive.

Michel
A: 

You cannot connect to mapped drives with a service. A mapped drive has to interact with memory called the desktop heap which tracks the icons on the desktop. Services do not have access to that memory. If you have to use a dsn create a systemdsn. better would be to use a connection string and store that in the app.config and use the encryption api to encrypt the user name and password.