Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have developed a project on VB.net with SQL server compact edition 4.0 as a database and deployed it in many machines, but now I am going to provide an update to the application which has more tables in database.

The issue here is that my clients have their data in database and i dont want them to loose it. But if i kept the same database in backend so my new update will not work on that database i need to add table to their existing database to allow my application to work on their system.

I am willing to add new tables to database in setup project, means when my client runs the setup the tables are added to their existing database.

I think so the question above is well clear and understandable, so please help me.

Thank you in advance.
Posted
Updated 22-Feb-15 3:33am
v2

If I understood correctly, one possibility is that your app adds the missing tables when starting. To add a table is basically the same as for example updating a row, you simply execute a SqlCommand. Only this time you have a CREATE TABLE statement in the CommandText.

The person who is issuing the command just needs to have proper privileges in order to create the table (dbo for example).
 
Share this answer
 
Comments
Kashif Alvi 22-Feb-15 9:38am    
Yes i thought about that solution but i want to add a table while installing the application. Is there any way to do this by editing my setup project.
Wendelius 22-Feb-15 9:42am    
What setup mechanism/program you use?
Kashif Alvi 22-Feb-15 9:45am    
Visual studio setup project
Wendelius 22-Feb-15 9:52am    
In that case have a look at Extending Visual Studio Setup Project[^]
Since you are using Compact edition, the way I'd go is to provide a complete new database, and transfer their data over, rather than trying to add anything to the existing file. That way, if there is any problem in the update, the customer doesn't lose anything.

In theory, adding a table programmatically to a DB shouldn't cause any problems anyway: it's just a case of issuing the CREATE TABLE command:
C#
string sql = "CREATE TABLE NewTable (LastName NVARCHAR(40) NOT NULL, FirstName NVARCHAR(40) NOT NULL, EmailAddress NVARCHAR(256))";

And that won't affect existing data - but Databases can be delicate, as can the people who depend on them! I'd create a new DB completely, and make sure they are kept happy.
 
Share this answer
 
Comments
Kashif Alvi 22-Feb-15 9:44am    
Yes i can do that, creating a new database and transferring the data to the new database, but how would i do that programitically
OriginalGriff 22-Feb-15 9:55am    
Interestingly, SQL Compact will treat any zero-length file as a valid database.
So the easiest way is to use Path.GetTempFileName (which creates a zero length temporary file for you) and then connect SQL CE to that to create the tables. When you've finished, you can move it to it's final destination.

Or you could read this:

http://arcanecode.com/2007/01/25/create-a-sql-server-compact-edition-database-with-c/

Which does it the "proper" way.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900