471,325 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

dynamic path

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"
Feb 14 '06 #1
6 8971
Hi

Windows Service has a different initial Working directory.
Debug.WriteLine(Environment.CurrentDirectory.ToStr ing());
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.

Feb 14 '06 #2
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("dbpa th");

it runs fine

""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:D9**************@TK2MSFTNGXA01.phx.gbl...
Hi

Windows Service has a different initial Working directory.
Debug.WriteLine(Environment.CurrentDirectory.ToStr ing());
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.

Feb 14 '06 #3
Ankit Aneja wrote:
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("dbpa th");

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

Feb 14 '06 #4
can u give me code example
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Ankit Aneja wrote:
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("dbpa th");

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

Feb 14 '06 #5
thanks
solved
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Ankit Aneja wrote:
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("dbpa th");

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

Feb 14 '06 #6
pathdb=System.IO.Path.GetDirectoryName(System.Refl ection.Assembly.GetEntryAssembly().Location);

pathdb=pathdb+@"\database";

solved

"Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
can u give me code example
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Ankit Aneja wrote:
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("dbpa th");

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


Feb 14 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Stephen Gennard | last post: by
2 posts views Thread by Justin | last post: by
1 post views Thread by Director - Minvent | last post: by
7 posts views Thread by Mike Livenspargar | last post: by
8 posts views Thread by Sandy Pittendrigh | last post: by
4 posts views Thread by Deere | last post: by
6 posts views Thread by Bill Spotz | last post: by
4 posts views Thread by aarklon | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.