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.
Related
We have a third party application where data is entered manually one record at a time where the user reads data from an Excel spreadsheet.
I have been asked to enable a way to upload data to the SQL Server database from the Excel spreadsheets. This would save a ton of time and prevent mistakes during manual data entry. I've done this type of work before but with in-house programs. I need to find what processes are run when the Save button is clicked. Is there a way to determine this or something similar (like exactly what tables\triggers are involved besides the ones I already know of)?
To discover the database activity the best way is to set up a test copy of the application and a test database where there is only 1 person working. Then start a SQL Profiler trace and record what happens in the database after clicking the Save button.
That said, do not be at all surprised if you do not get a complete picture of what you need. This will not reveal anything that happens to the data within the client application before being sent to the database. Reverse engineering an application can be just as error prone as the manual effort involved with normal data entry. On top of it, there is no guarantee that that process will remain the same for updated versions of the application.
If you don't have access to the original source code, then you can enter something like this in SSMS to see which queries have been run recently by a specific machine (substitute in your host name in line 2 and then walk through the process to get a pretty good idea of what is going on). This was adapted from an existing answer on SO to work for a single host, but I have no idea how to track it down to give proper credit...
declare #host varchar(50)
set #host='MyComputerName'
SELECT TEXT
FROM sys.dm_exec_connections
CROSS APPLY sys.dm_exec_sql_text(most_recent_sql_handle)
WHERE session_id in
(SELECT des.session_id FROM sys.dm_exec_sessions des WHERE des.is_user_process = 1 AND host_name = #host);
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
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.