Is this possible to put any scripts with the Setup Project in .NET C# so that I can delete couple of rows from a table or to delete the entire tables from database while uninstalling the setup from control panel? I need all the data to be removed from its database when the windows application is uninstalled
You may have to define exactly what "it does nor work for me" means. That code is an uninstall custom action, but it won't be called unless you've added it to the setup project as an uninstall custom action, if that's what you mean by it not working. This stuff does work, assuming you add it as an uninstall custom action.
Another way in which it will not work is that you probably won't see a console.writeline working. This is not application code running in the interactive user's shell. This is a callback from an msiexec.exe process running with the system account, so it most likely won't let you do anything to interact with the interactive user's desktop, and it's not clear to me what happens if you attempt to write to the system account's console because I doubt that it has one. That also means that if you're going to add code to delete tables from the database then the database needs to allow access by the system account, something that might not be allowed by default.
Just delete tables from sql and then do unistallations
drop tablename
delete *row from tablename where condition
Related
I'm trying to retrieve data from a Textbox in Visual Studio Project Installer but I simply keep failing. I have no idea how to retrieve data from, let's say the EDITA2 field and it seems the internet has no answers so far.
The project I'm talking about is a windows service you install with the mentioned installer. In the installer you can configure the service. I want to get data like server IPs and computer names and I want to use this data later in the running service. Talking of service, is there a possibility to automatically start the service after installation?
Summing up, i want to write data from the installer to a text file and to start a batch file after the installation process is completet. Can you help me please?
Thanks in advance for an answer.
I think you are searching for Custom Actions
https://msdn.microsoft.com/library/d9k65z2d(v=vs.100).aspx
https://msdn.microsoft.com/en-us/library/9cdb5eda(v=vs.100).aspx
To setup the StartType of a Service you require a ServiceInstaller
Maybe this helps
http://www.docstorus.com/viewer.aspx?code=7c7ccc28-6503-4779-877e-f350faab6741
This is the documentation for the Textboxes user interface dialog:
https://msdn.microsoft.com/en-us/library/e04k6f53(v=vs.100).aspx
The identifier EDITA1 (and others) is a property name that you can use later in (for example) custom actions. Without knowing exactly what kind of custom action you might be thinking of it's hard to say how you use it. In general, specifying it as a parameter to the custom action as [EDITA1] will cause it to be resolved to its actual value. But if you just want to store the values in the registry you'd create a registry item with the value [EDITA1].
To start the service in Visual Studio setups that install services with installer classes you'd need to overwrite the Install method, calling base.Install() and then adding code to start the service. Similarly at uninstall or upgrade time you can override the Uninstall method and stop the service before calling base.Uninstall().
These posts have some Textboxes examples:
Overriding "Textboxes" dialog fields from the command line in MSI installer (Visual Studio 2010 Web Setup)
Setup Project: user enters a value then store it in a text file or database
Visual Studio setups are not very useful with services and UI. There is no way to validate what the user enters at the time it is entered - if you validate it with a custom action it will be at the end of the install and the entire install will fail and roll back. Windows Installer has built-in support to start/stop/delete/install services but VS setups don't use it. If this is something you do regularly it might be useful to consider another tool, and that might have a learning curve but the resulting MSI will be more reliable and easier to use.
Here's my situation. I have a desktop application that interacts with sql server. There will be one sql server and multiple applications will access the same database. Currently two computers are running the same application.
If I make a change in database schema, I will also have to make a change in the application and now the problem occurs.
Before change:
Table Invoice with columns
- title varchar(128)
After change:
Table Invoice with columns
- title varchar(128)
- content varchar(128)
Computer A uses the old application that does not have any information about that new column "content" and Computer B uses the new application.
Because A is using the old app, it will insert null values to the table and B will face null pointer exception.
I cannot think of any other way since the old app cannot just terminate and download the newest version in the middle of a transaction. And I don't think it's a great idea to be like tell people don't use the app within downtime and restart the app after.
How does a website handle this? I think all of the websites will face this issue.
What is the proper way to prevent this to happen?
Please point me to the right direction
There are some options to do it. For example:
Using ClickOnce deployment, you can specify a minimum required version for the application in the Application Updates dialog box. You can also check it programmatically using code while the application is running.
Also if you don't use ClickOnce, you can keep the minimum required version of your software in database and the at start of your application check the version from database and if the current version is less that minimum required version, then don't run the application. Also you can check it programmatically while the application is running if you need.
var version = Assembly.GetExecutingAssembly().GetName().Version;
You can query a record in the database that tells you what is the minimum version of the app that is compatible.
A quick and dirty solution would be to write a trigger for insert that would write a default value to the new column ("content). Alternatively (easier) use a default value for your column.
I'm building an application which will use some settings and a local SQL Server. My question is, when it comes time to update the application; will the settings or data be overwritten?
What happens if I want to change some tables around in the future?
Frankly, I've always thought that ClickOnce's way of handling data is dangerous. If you deploy a database with ClickOnce, it puts it in the DataDirectory. Then when you deploy an update to the application, it copies the database forward to the folder where the next version of the app is installed. But if the database changes, it copies it forward to the folder + \pre, and puts a new one in the datadirectory. If you don't realize you changed it, it replaces it anyway. If you so much as open a SQLCE database and check out the data structures, wham it gets deployed. Surprise!
I think storing the data in another folder under the user's profile makes more sense, and is safer. Then YOU can choose when to update your database. This article will show how to move your data so it's safe from ClickOnce updates.
Additionally, when you DO want to make changes to your database, you can use SQL statements to do so, such as "ALTER TABLE" and so on. I've created a script and deployed it as one long string (with carriage returns in it) and had the application split the resource apart by carriage return and execute the statements one by one. You get the general idea.
One comment about user settings -- You can change these programmatically via the UI (i.e. give the user the capability). But note that if you change the certificate of your application and are running a high enough version of .NET (3.5, 4), it won't cause you a problem per se, but it DOES have a different identity as a ClickOnce application, and the user settings are not carried forward when the next update is published. For this reason, I also rolled my own XML file for config data, and I store it in LocalApplicationData as well.
User-level settings will not be overwritten during an update via ClickOnce, but you can push new application-level settings, because the [YourExeName].exe.config file will be overwritten during an update.
If you need to overwrite user-level settings, you will have to do this programmatically.
Just a quick question:
I'm in the finalizing state of my current C# project, and I'd like to send a version out to people that has 90% of the features initially requested, but it'll be a version of the software that will do all they need - they need the software as soon as possible, basically.
Therefore I'm going to be using the online install option in VS2008 that will use updating to add the final few features, as well as additional things, later. What I'm wondering is the following:
The program will come packaged with a .mdf file. When I create a new version of the program however, I don't want to change all of the data that has been added to the database already. My question is how do I go about doing this?
Thanks!
How are you planning to distribute the update? An installer will have flags indicating when a file should be replaced. (Date, version etc)
One-Click installation has the ability to check for changes on program startup.
I am writing a c# application. I need to integrate update feature to this application (ie, the application should check if a new update is available and should update to new version if available). How can i do that.
Thanks
Take a look at the ClickOnce Deployment.
The Auto Update feature in ClickOnce Deployment
If you want to write your own solution then you should have a separate program that will do the update as you can't update any dlls that are already in use, so this new program must not share any dlls with the actual program.
I think the best approach would be to make an http connection, if you are downloading the updates, and send your version number, and have the server determine if there is an update, depending on specifics, such as whether the update is for a 64-bit OS or 32-bit, for example.
But, allow the user to pick how the update works, I think the Google Chrome solution is bad, as it updates silently, but doesn't even tell you that there was an update. I prefer if I can pick to update automatically, or just download automatically, so I can pick when to do the update.