Multiple winforms projects - need to alter app.config files at time of install - winforms

I have a winforms solution with multiple projects (UI, web services, data access). All of these projects have their own app.config file. At install time, I need to change the connection string in the data access project based on user's database configuration.
But the data access project creates a dll at install time, with no app.config file available for updating. The UI project is the only project with an app.config file created. And the UI project has a reference to the data access project, so I don't believe the data access project can "see" the config settings of the UI project.
I have searched SO for an answer but have not found anything specific to this situation. Am I doing something wrong in how my projects are set up? Any help would be appreciated.

For anyone else facing this issue:
I believe I found the answer here
In Visual Studio, on the properties of each config file, you can choose "Copy Always" for Copy to Output Directory. This will explicitly create the config file for dll projects.
Then in InstallShield, you can refer to this config file ("MyApplication.dll.config" for example), and alter the connection string through the "Text File Changes" section under "System Configuration". When the user is prompted to connect to a sql server, InstallShield can use those connection properties to alter the connection string in the config file.

Related

WPF install : creating and saving database location

I have a WPF C# app which I have created which uses an Access Database (accdb).
I am using Inno for an installer.
I currently have a static path the database in my app.config connectionString section, however what I need is to:
run INNO
ask if this is the Master
YES: install the DB file in C:/MyApp
NO: do not install the DB file, but messageBox asking for the database location (BROWSE and verify Name) - as they will have to look on network.
This browse location answer would then replace the C:/MyApp with //192.168.1.2/C/MyApp for example in the AppConfig connection string section...
Does that sound reasonable or possible (or even 'correct' to do?)
I'm new to C# and this is my first install/deploy I've done so I am very fresh on this.
The other option I was looking at would be to ask to install the database.
If they say NO then just carry on with install.
When the wpf starts up and cant locate the database then I can code in a browse feature in the app which then writes to the appconfig file.
Which is the more Correct way to proceed or is there another option which I am oblivious to which is how it should be done?
Aside from correctness, one advantage to picking the DB location in the app is if the location ever changes. If you do it in the installer, they would have to reinstall.
I would probably go with installing the app as "master" by default, but also provide an option for the user to change this. Then the installer is simplified and doesn't really have to contain any application logic.

How to recover DNN Site

One of our client has a DNN Site. There was some issue happened in the server and the drive that host the site is crashed. Luckily the database was in other drive. So we have database of the site. I have a back up of the site in my local system too. Now I need to restore the site. So My question is what steps should I perform exactly?
Below are some twists that I came to know recently:
There were other sites too and they were in different DNN version. Can we know from database which version of DNN was the sites running?
I tried to put my files on server and provide connection string of database. When I start the site, it complete the installation process, but shows me default DNN Page. Please see attached image for the same.
When I checked the Log file, it is throwing below error
Unhandled error loading module. ---> System.Web.HttpException: The
file '/Portals/_default/Containers/Xcillion/NoTitle.ascx' does not
exist
DotNetNuke.Services.Exceptions.Exceptions -
DotNetNuke.Services.Exceptions.ModuleLoadException: Unhandled error
loading module. ---> System.Web.HttpException: The file
'/Portals/_default/Containers/Gravity/Title_h2.ascx' does not exist.
DotNetNuke.Services.Exceptions.Exceptions -
System.NullReferenceException: Object reference not set to an instance
of an object.
DotNetNuke.Services.Exceptions.Exceptions -
DotNetNuke.Services.Exceptions.ModuleLoadException: Unhandled Error
Adding Module to ContentPane ---> System.NullReferenceException:
Object reference not set to an instance of an object.
Then I thought the site may use the inbuilt database (I am not remembering exactly what kind of database I set up). So I copied the site code in separate folder and tried to map this folder with IIS. And that is giving me below error:
DotNetNuke.Common.Initialize - The connection to the database has failed, however, the application is already completely installed, a 500 error page will be shown to visitors"
Can anyone tell me how can I recover this site?
Thanks in Advance.
Ouch!
Having the database (or databases) is a good start.
Look in the Versions table and the last row is the last DNN Version installed. Look in the Portals table to see which portals were created in that install.
The errors that refer to Containers refer to files that are missing from the site's file system. Your IIS configuration for the site points to the root of the file system.
The module load exception probably refers to a module's files that should be in /DesktopFiles/ModuleName.
So, if you have the database AND you have a copy of the files that correspond to the database, then put them all back, make sure that the connection strings are pointed correctly in web.config ... and cross your fingers.
If you have the DNN version and the correct database, you might try doing a clean install of the DNN, install the modules that you had installed on the one that crashed, and THEN swap the clean version's database with the one that you have -- actually a copy.
Make sure that you are keeping copies, and you may be able to reconstruct lots of things.
And, it goes without saying that you should take a blood oath about making good and regular backups, and storing them on a different disk.

Best practice with ClickOnce Deployment application settings

I have a question regarding a WinForm application and ClickOnce Deployment.
Currently, I use the Visual Studio Installer for creating my installer. One of the things that I do is I have created a custom installer class that I use for entering in certain information (servername, database name, username, password, port number - which is needing for my connection string to the DB). This information gets written to my app config file. However, this makes updates a pain, so I am looking into ClickOnce Deployment instead.
For those of you that do something similar, what's the best way to go about handling this? Is it possible for me to include a config file with my ClickOnce Deployment project that will just copy the settings from that file during the installation? Or, what is the recommend best practice for handling this?
Thanks everyone.
My ClickOnce application also accesses a database. I created a separate program that asks for the database information and encrypts it into a .DAT file. The .DAT file is added to the main program. You must change a setting on the file to Content so that it is included in deployment. The main program opens the .DAT file and decrypts it for the information. This way no one that uses the program knows any of the database information.

No connection string named 'MyApplicationEntities' could be found in the application config file

I just install EF 4.3 and trying to upgrade my project with migration. however I am getting issues with trying to execute add-migration initial to my project via Package Manager console.
It is throwing any exception now No connection string named 'MyApplicationEntities' could be found in the application config file.
Now my config has it all
<connectionStrings>
<add name="MyApplicationEntities"
connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=MyApplicationEntitiesDB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
I am not sure what is the issue is it a bug in EF 4.3 or there is something I am not doing right.
I thought this post has solved the issue but not quite.
Anyone got an answer.
Appreciate Sanj.
Ah, figured this out accidentally.
I had to remove
public MasterEntities()
: base("name=MyApplicationEntities")
// ^^^^^
{
}
to
public MasterEntities()
: base("MyApplicationEntities")
{
}
EF 4.3 does not like connection string being called name=xxxxx
The solution as Sanj pointed out is that you need to copy the connection string from your database project's App.config to the web project's web.config. I'm not sure why the above answer is marked as correct. I'm adding this as an answer instead of a comment so future readers will spot this.
I had the same error but I already had a web.config file with the correct connection string name and a DbContext declared correctly. However, I noticed when I ran add-migration with -Verbose it state the 'Startup Project' as a different project than the one containing my context. So I change the Startup Project, re-ran the add-migration and it all worked!!
Make sure your statup project config file has the connection string.This link may help you.
I also had this problem and solved it by
Selecting the correct StartUp project.
Rerunning the command on Package Manager Console.
Things worked out as expected.
I also encountered the similar exception. AppConfig is originally gets created in the project that we generate the entity model.
But if you are executing the application using some other project (there are several Projects in my solution), the AppConfig needs to be included in the project which is being executed.
1. ctor => Context
public MasterEntities()
: base("ConnectionStringName")
{
}
2. config file
<add name="ConnectionStringName"
connectionString="Data Source=.;Initial Catalog=DatabaseName;User Id=sa; Password=YourPass;"
providerName ="System.Data.SqlClient" />
3. in Sulation Exporer right click the project and select 'Set as
startup project'
4. in PackageManagerConsole Change Default Project to Your Project of
context class.
5. then:
add-migration new
or added ConnectionString to config file of working Project.
In my case, i got two projects:
I just have to copy the connection string from DAL App.Config project to WPF App.Config project
If you get this error and you're working with Oracle DBs in .NET, check your existing <connectionStrings> tag in the startup project (web.config in web projects, app.config in console/Windows projects), and make sure Oracle didn't replace it with nonsense.
Installing the Oracle.ManagedDataAccess.* assemblies from NuGet does this obnoxious thing where it deletes whatever <connectionStrings> tag that already existed in destination project and replaces it with a new one at the bottom containing a boilerplate Oracle connection string.
Do a git diff or whatever you use to diff changes and focus on your *.config files. Restore old connection strings as needed, then rebuild and try again.
For all others, just remember that the <connectionStrings> tag is only read from the startup project's configuration (aka the entry assembly). If you have your DB stuff in another project that is referenced by your startup project, and you have an app.config in that DB project with a <connectionStrings> tag in it, that tag is only used for for scaffolding EF stuff. After that, the DB project reads the tag from the startup project's configuration instead of its own.
For anyone arriving here because they are getting this error while working with WPF in Visual Studio, please take a look at this post:
Does MVVM stop the ability for the Visual Studio Designer to show xaml?

Reading Properties of all Files existing in one of the folders on Application Server and print on a JSP

I have to read the Name and Creation Date/Last Modified Date of all the files that may exist on /product/xyz folder, existing on JBoss Application Server and print the same on JSP.
This folder is being loaded with the fresh files when server is booted. The framework used is Struts 1.2.
Any hints or examples around how to read these information and print on JSP? Thanks!
EDIT :
I understand that it is much easy to read the files from a folder which might be part of my workspace folder. But, this is a different scenario.
Here, the JSP file will be deployed on JBoss application server, in some ABC folder, as part of some EARs. On the same application server, there is some other XYZ location, which will be loaded with the fresh files, when server is booted. I want to read the files existing in that XYZ folder. I Hope the scenario is more clear now.
The code doesn't change whether I try to access the files from my Work Space folders (Rather, which are to be part of EARs) or I may access from the Server File System (Outside the EARs).
The issue could be there in Path Mentioned or the Permission (Read/Write) to the Folder from which the files are being read.

Resources