dynamic path

A

Ankit Aneja

My service is running fine
when i give full path like this
"E:\c# windows\clamservice\bin\Release\database"

but when i tried for dynamic

"/database"

it compiles well but when i go to Computer Management ->Services and start
it ,it gives

"The clamservice on local computer started and then stopped.Some services
stop automatically
if they have no work to do,for example performance logs and alerts service"
 
P

Peter Huang [MSFT]

Hi

Windows Service has a different initial Working directory.
Debug.WriteLine(Environment.CurrentDirectory.ToString());
The result will be C:\WINDOWS\system32, the result may differ according to
where you install Windows.

That is to say it will check the C:\WINDOWS\system32 for the relative path.

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

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

Ankit Aneja

i tried like this

pathdb=Environment.CurrentDirectory.ToString();

pathdb=pathdb+@"\database";

p.Database.Path=pathdb;

but still at time of start it starts and then stops

and when using hardcoded path from config file

//pathdb=ConfigurationSettings.AppSettings.Get("dbpath");

it runs fine
 
J

Jon Skeet [C# MVP]

Ankit said:
i tried like this

pathdb=Environment.CurrentDirectory.ToString();

pathdb=pathdb+@"\database";

p.Database.Path=pathdb;

but still at time of start it starts and then stops

and when using hardcoded path from config file

//pathdb=ConfigurationSettings.AppSettings.Get("dbpath");

it runs fine

As Peter said, the CurrentDirectory property won't be what you expect -
unless you really *have* got a directory called "database" under
c:\Windows\System32, which I really hope you haven't...

You might want to look at Assembly.GetExecutingAssembly() and work out
where the assembly is, so you can make a path relative to that. (You
can find the path using
Assembly.GetModule(), then Module.FullyQualifiedName.)

Jon
 
A

Ankit Aneja

can u give me code example
Jon Skeet said:
As Peter said, the CurrentDirectory property won't be what you expect -
unless you really *have* got a directory called "database" under
c:\Windows\System32, which I really hope you haven't...

You might want to look at Assembly.GetExecutingAssembly() and work out
where the assembly is, so you can make a path relative to that. (You
can find the path using
Assembly.GetModule(), then Module.FullyQualifiedName.)

Jon
 
A

Ankit Aneja

pathdb=System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

pathdb=pathdb+@"\database";

solved
 
A

Ankit Aneja

thanks
solved
Jon Skeet said:
As Peter said, the CurrentDirectory property won't be what you expect -
unless you really *have* got a directory called "database" under
c:\Windows\System32, which I really hope you haven't...

You might want to look at Assembly.GetExecutingAssembly() and work out
where the assembly is, so you can make a path relative to that. (You
can find the path using
Assembly.GetModule(), then Module.FullyQualifiedName.)

Jon
 

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