i have 2 exe files named as ActiveGateway.exe and ActiveLBS.exe which is running on window service ACTIVEServer and i copied that service and change its name as ActiveServer1 and 2 exe as Gateway.exe and LBS.exe.and change the installation path .after this if we trying to insatl this service it shows an error.this version already exist.i changed the version number product name and all..but still issue is like this
All that needs to be done is to make sure that the name of each service installation instance is unique. Then you need to have copies of installation directories for each service instance you'd like to have. Finally, you need to be able to set the service name dynamically during installation and startup. This will be facilitated using the app.config file.
The cleanest and most readily available way of providing the service name is to use an app.config file for your service and create an appSettings key that can be read from to set the service name. An app.config file needs to be added to your solution if one doesn't already exist to store the unique service name in order to dynamically set the ServiceInstaller.ServiceName and the ServiceBase.ServiceName to the same service name value you added to your configuration.
Source: http://www.codeproject.com/Articles/21320/Multiple-Instance-NET-Windows-Service
Related
I want to have my Worker Role (have not done this with a web role) upload a file when it is deployed and also be able to access that deployed file in code.
How do I deploy a file with my Cloud Service to each instance?
How can I find that file in code?
Good question, Adam. To deploy a file with your cloud service you can follow this article. The 2 main points are as follows:
set Build Action to None
set Copy to Output Directory to "Copy if newer"
With these two properties set the file and its folder structure will be copied to your instance deployment. Things brings us to accessing that file in code.
To access it in code simply do the following which I got from here:
string appRoot = Environment.GetEnvironmentVariable("RoleRoot");
string pathToFiles = Path.Combine(appRoot + #"\", #"approot\" + "anyFolderNameIUsed\");
It is important to remember that this is part of the deployment package which means this file will be overwritten whenever the deployment is completed again. Also, each instance will have it's own version of the file.
If you need persistance or the ability to share file contents between your worker roles you can save your files in Blob Storage. The following article can you help accomplish this.
Using Blobs
I want to add OleDb(MS Access DB) to My Project(C# App) and Deploy it to Customer .The Db Should be installed with exe's and dll's such that we can obtain the path of DB,Write Data to it.
I really want the code where we can get the path of DB and for Connection String
In main exe use path in connection string as:
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),"DB.mdb")
for dll use Assembly.GetCallingAssembly().Location if it is in different folder otherwise above will also work.
Below is the code i am using to update or change the values in appsetting in app.config
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["userName"].Value = username;
config.AppSettings.Settings["pwd"].Value = pwd;
config.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection("appSettings");
i am using above code to change or update the settings in appsetting section at runtime and want the changes to persist so that when i run the application it should pick the new values from appsettings but here it doesn't happen so the changes made and saved at run time do not persist when i relaunch my application again it has the old default settings. Also i checked app.config in bin/debug but it too had the old values in appsettings. i refered various blogs and post here too as a reference but it got the same code as above but it did not persist the settings.have referred this post
I had the same problem while ago. I would have preferred to put this in a comment but I don't have that privilege. My answer might not be your case but I think is worth to be shared.
May I ask you where your bin folder is located? Windows 7 when you programmatically alter a file that isn't in a user accessible space creates a copy of that file in a Roaming space and there the file will stay. Every time you try to access the file (like your app.config) W7 transparently redirect your readings/writings to this file, so there's a chance that you are modifying the file in the roaming space, leaving the one you are lookin unaltered.
Are the changes you are making still there the successive time you start the application?
Disclaimer/Apology: I'm not an experienced user so if I am saying silly things let me know and I will remove this comment.
See below(from MSDN) and remember app.config is in your project. .exe.config is the actual file name.
Client applications use a global configuration that applies to all users, separate configurations that apply to individual users, and configurations that apply to roaming users. The userLevel parameter determines the location of the configuration file being opened by indicating whether it has no user level (the configuration file is in the same directory as the application) or has a per-user level (the configuration file is in an application settings path determined by the user level).
Specify which configuration to get by passing one of the following values for userLevel:
To get the Configuration object that applies to all users, set userLevel to None.
To get the local Configuration object that applies to the current user, set userLevel to PerUserRoamingAndLocal.
To get the roaming Configuration object that applies to the current user, set userLevel to PerUserRoaming.
NoteNote
To get the Configuration object for a resource, your code must have read permissions on all the configuration files from which it inherits settings. To update a configuration file, your code must additionally have write permissions for both the configuration file and the directory in which it exists.
i got my solution of above problem, my goal was to persist changes done at run time at application or user level. Initially i tried using App.config where i kept default settings for application in appsettings section of app.config, but later after research i got to refer i got to know appsetting does not persist the changes, instead you can use userSettings section where under YourApplication.Property.Settings you can give your userlevel settings and it worked for me. To do this you do not need to go to App.config to do it manually, rather you can do it from the property window of project.
Right Click on your project -> Select Settings Tab on the left-> Now on the right hand side you will see the Resource section , give the ResourceName, Type, Scope and its value and you are done. The same value can be access and change dynamically from Code as well.
Below are Code Excerpt for the same --
Accessing Settings Value
enter code here
userName = Properties.Settings.Default.UserName;
pwd = Properties.Settings.Default.PWD;
Saving New Settings Back
enter code here
Properties.Settings.Default.UserName = userName.ToString();
Properties.Settings.Default.PWD = newPWD..ToString();
Properties.Settings.Default.Save();
And when you will launch your application next time you will get the new changed settings as your default settings.
I hope that helps
Thanks Guys
VJ
I created a simple WCF service In solution and added a console application project to the solution to call the WCF service. When i debug chat solution it give me the following error. The WCF service was working fine when i tested it.
ServiceHost host = new ServiceHost(typeof(EvalService));
Resulting error:
A child element named 'service' with same key already exists at the
same configuration scope. Collection elements must be unique within
the same configuration scope (e.g. the same application.config file).
Duplicate key value: 'EvalServiceLibrary.EvalService'.
(C:\Users\User_Name\Documents\Visual Studio
2010\Projects\ChatSolution\ConsoleHost\bin\Debug\ConsoleHost.vshost.exe.Config
line 14)
I got the same error, but in my case I was creating a service using a previously used name. Sometimes, even if you delete the service file/code from the solution, its corresponding definition in the App.Config file remains un-updated.
I did a Quick Find (Ctrl+F) over the whole solution and typed the name of the service I was using. It located the piece of code in the App.Config file where the service is defined.
I deleted it and created the service using the same name.
It's all written in the exception message. You have two services in your app.config defined with the same key. Just look through the app.config in your console app, it shouldn't be hard to find.
I'm trying to create a windows service and I need it to be able to write to the event logs. I've added an EventLog component to my Service project, and set the Log property to be ccs_wscln_log and the Source property to be ccs_wscln (same name as the service).
I have also created and installer for this project. My problem is that whenever I install the service, it creates the ccs_wscln registry key under
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application
when it SHOULD be
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\ccs_wscln_log.
The problem with this is that when I try to launch the service, I get an error that says
"The source 'ccs_wscln' is not registered in log 'ccs_wscln_log'. (It is registered in log 'Application'). The source and Log properties must be matched, or you may set Log to the empty string, and it will automatically be matched to the source property'.
I've found that if I delete the ccs_wscln registry key under the Application folder, when I start the service it will run and generate the ccs_wscln_log entry under EventLog. So my question is, when I install the application, why is it creating an entry for me automatically under Application, and how do I prevent it from doing this?
I found another post on SO that said I need to restart my computer if I had installed it before under Application, so I tried that but when I reloaded the solution, I couldn't even bring up the designer because it was complaining that the registry entry was missing and it would still install under Application anyways.
I created a tutorial for creating a Windows service from scratch using C#. I address the issue of writing to an application-specific log. See Step 9 here for details.
I think, you would need following in your ServiceInstaller class.
this.Installers.Clear();
Above code needs to be just before you are adding a range of installers.
That is because, EventLogInstaller is added by default. Calling clear will remove it.
Alternatively, you can loop through the installers collection, select the specific type (EventLogInstaller) and assign it required LogName and EventSource name.