Windows service and VFPOLEDB

  • Thread starter Adam Klobukowski
  • Start date
A

Adam Klobukowski

Hello

I've written a small C# program that uses VFPOLEDB it is working
perfectly. Then, I redesigned it to work as service (as described in
http://msdn.microsoft.com/library/d...kthroughcreatingwindowsserviceapplication.asp).

Unfortunetly, now my service is unable to use VFPOLEDB, stating that it
"is not registered" on my local machine.

Service is installed on LocalService account.

I suspect this has something with security policies, but I don't know
where to start :(
 
N

Nicholas Paldino [.NET/C# MVP]

Adam,

That error indicates that it would be something else than it not being
registered, but if it works for a normal application, then perhaps the error
is incorrect in itself.

There is an easy way to test this. Basically, make the service run
under the same user account which you ran the application on before you made
it a service. If it works, then you know it is a rights issue, otherwise,
it is an issue with the VFPOLEDB driver.

Hope this helps.
 
A

Adam Klobukowski

Nicholas Paldino [.NET/C# MVP] napisa³(a):
Adam,

That error indicates that it would be something else than it not being
registered, but if it works for a normal application, then perhaps the error
is incorrect in itself.

There is an easy way to test this. Basically, make the service run
under the same user account which you ran the application on before you made
it a service. If it works, then you know it is a rights issue, otherwise,
it is an issue with the VFPOLEDB driver.

Hope this helps.


I tried it usnig LocalSystem account, and I have the same error. When I
tried to intall service as local user, I always had unknown
account/wrong pasword error, but they were ok.
 
W

Willy Denoyette [MVP]

Check if you have HKEY_CLASSES_ROOT\VFPOLEDB.1 in the registry.
If this key is not available, it means that it's installed as a User
component not as a System component, and that also means it should be used
from a Users context NOT from a service context.
However, if you want to try it from a service, you can run "regsvr32
vfpoledb.dll" and hope the keys are added to HKCR, if not you will have to
copy them manually from HKCU.
Note also that probably the COM classes have to instantiated in a STA,
Services have their threads running in an MTA, so you will have to spawn
another thread and initialize it's apartment state for MTA and access your
VFP components from this thread.

Willy.



Adam Klobukowski said:
Nicholas Paldino [.NET/C# MVP] napisa³(a):
Adam,

That error indicates that it would be something else than it not
being registered, but if it works for a normal application, then perhaps
the error is incorrect in itself.

There is an easy way to test this. Basically, make the service run
under the same user account which you ran the application on before you
made it a service. If it works, then you know it is a rights issue,
otherwise, it is an issue with the VFPOLEDB driver.

Hope this helps.


I tried it usnig LocalSystem account, and I have the same error. When I
tried to intall service as local user, I always had unknown account/wrong
pasword error, but they were ok.

--
Semper Fidelis

Adam Klobukowski
(e-mail address removed)
 
A

Adam Klobukowski

Willy Denoyette [MVP] napisa³(a):
Check if you have HKEY_CLASSES_ROOT\VFPOLEDB.1 in the registry.

Yes, there is. Both VFPOLEDB and VFPOLEDB.1
If this key is not available, it means that it's installed as a User
component not as a System component, and that also means it should be used
from a Users context NOT from a service context.
However, if you want to try it from a service, you can run "regsvr32
vfpoledb.dll" and hope the keys are added to HKCR, if not you will have to
copy them manually from HKCU.
Note also that probably the COM classes have to instantiated in a STA,
Services have their threads running in an MTA, so you will have to spawn
another thread and initialize it's apartment state for MTA and access your
VFP components from this thread.

Whoa, STA? MTA? (mail transfer agent? ;) )... where can I read something
about it?

I also thought about using a System.Diagnostics.Process to spawn process
from service that would do what my service would ask it to. Would it
work that way (ie, spawned process would use VFPOLEDB).
 
A

Adam Klobukowski

Willy Denoyette [MVP] napisa³(a):
1. If you have version 8.0.0.3006, download the latest vfp provider from
http://msdn.microsoft.com/vfoxpro/downloads/updates/default.aspx
2 Install
3. Re-reg the COM server by running regsvr32 "C:\Program Files\Common
Files\System\Ole DB\vfpoledb.dll"
(supposed this is the correct path).

I have version 8.0.0.3117 (I reinstlled it to be sure I have latest
varsion, and I had).

This is the transcription of the exception that happens (translated from
polish, so may be not 100% accurate):

System.InvalidOperationException: Dostawca 'VFPOLEDB.1' is no registered
on local computer. ---> System.Data.OleDb.OleDbException: No avialible
information about error: REGDB_E_CLASSNOTREG(0x80040154).
--- End of trace ---
at System.Data.OleDb.OleDbConnection.CreateProviderError(Int32 hr)
at
System.Data.OleDb.OleDbConnection.CreateProvider(OleDbConnectionString
constr)
at System.Data.OleDb.OleDbConnection.Open()
at Hanyang_Usluga.HanyangUsluga.OnStart(String[] args)

Connection string is checked and is 100% ok. (Works in program that
doues exactly the same but is not a service).
 
A

Adam Klobukowski

I went a bit around the problem. I copied VFPOLEDB registry keas from
HKCR to HKLM\SOFTWARE\Classes. The 'unregistered VFPOLEDB' problem is
gone, but any first operation on the database (SELECT for example)
throws invalid path or filename exception (but path and file (table)
name is ok - double, triplechecked).
 
W

Willy Denoyette [MVP]

Adam Klobukowski said:
I went a bit around the problem. I copied VFPOLEDB registry keas from HKCR
to HKLM\SOFTWARE\Classes. The 'unregistered VFPOLEDB' problem is gone, but
any first operation on the database (SELECT for example) throws invalid
path or filename exception (but path and file (table) name is ok - double,
triplechecked).

--
Semper Fidelis

Adam Klobukowski
(e-mail address removed)

Adam,

Please don't hack the registry, do as I asked from the beginning, run as
administrator and re-register the DLL using regsvr32.

Now up to your next problem, If you VFP files are on a local disk, make sure
the service account has access to the files, so check your ACL's.
If your VFP files (what you call a Database) happen reside on a network
share, you are probably running in the security context of a service which
has no network access. In this case you will have to run your service with a
domain account's credentials.

Note that all these problems are due to the fact that you are using a
personal desktop style database as a server product.

Willy.
 
A

Adam Klobukowski

Willy Denoyette [MVP] napisa³(a):
Adam,

Please don't hack the registry, do as I asked from the beginning, run as
administrator and re-register the DLL using regsvr32.

I did so, it didn't help.
Now up to your next problem, If you VFP files are on a local disk, make sure
the service account has access to the files, so check your ACL's.
If your VFP files (what you call a Database) happen reside on a network
share, you are probably running in the security context of a service which
has no network access. In this case you will have to run your service with a
domain account's credentials.

Note that all these problems are due to the fact that you are using a
personal desktop style database as a server product.

I worked around the problem by changing the account that service works
to Admin (that is 'Administrator' in polish version), and now it works
flawlessly.
 

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