Delete the Database - sql-server-2005

I am using MS SQL Server Management Studio Express. I have installed "MyDatabase.msi" in my machine.So "Mydatabase" database have created with tables in MS SQL Server Management Studio Express automatically after the installation.It was working fine.yesterday I have uninsatlled the "MYDatabase.msi" from control panel,But the database and tables are still in MS SQl Server Management Studio Express.Why it is not removed? I want to remove the database while uninstall process. So how to do that?

UIninstall won't automatically remove the tables and data you added to a db on the system. If you wrote code to add that data then you need to write code to delete it.
I can't tell from your post if the db file is being physically left behind on the system too. If it is, I suspect you created it from scratch in the app or with code doing the install. Either way, if you create it then you need to remove it. Uninstall will not remove that db file unless it was installed as a file by the MSI like your other files were. So you can add it to your setup and populate it with your code, then uninstall will delete it, or add an uninstall custom action to remove it or depopulate or whatever it you want to do about it.

Related

Creating a local database from server database in visual studio

I have a rather large database I am working with and I am about ready to break something. To prevent this affecting live data, how would I use the live database to setup a local database? Not sure if this is even possible but I do know you can setup a local db.
You can create a SQL Server Data Tools database project type, then right click the project file and do an "Import..." to import the database to your local machine. Then you can deploy the local DB and it will be available in the SQL Server Object Explorer locally. This way you don't have to install SQL server on your machine - everything's in Visual Studio. Hopefully you are developing with a small set of data locally.
Answer
Use Visual Studio's Data Comparison tool to synchronize data to your target database from your source after you've created the database (schema only, no data) in your local database server.
Steps
From the Visual Studio's SQL Server Object Explorer:
A. Create the local database
Add two SQL Server Objects: One that connects to your production server and one that connects to a local (development/testing) server. If you need help setting up a local server then take a look at SQL Server LocalDB
Add a New database in your local server to receive the data (don't over think this step).
B. Migrate the Schema
Right-click the source (production) database and click Schema Compare...
From the SQlSchemaCompare tab that opens, use the Select Target dropdown to select your local database as the target.
From the SQlSchemaCompare tab, click Compare.
Uncheck everything in the comparison results except for the Tables, Views, and Procedures (unless you know what you're doing) then click Update.
C. Migrate the Data
Right-click the source (production) database and click Data Comparison...
Follow through the prompts to select the Tables to migrate then click Finish.
From the SQlDataCompare tab that opens, review the comparison results (it should make sense to you) then click Update Target
That's it! Either your local database is ready with data, or you confused your target/source and wiped out all of your data in production. Either way, you're done for the day.

Add a data connection to TFS version control

I am working on a visual studio web project in express 2013.
I also created a (localdb)\v11.0 data connection and added a bunch of tables and stored procedures.
My question is how can I check in this data to TFS version control?
The website project I am working on is already in TFS. I looked around and I see that I can add a sql project and then create tables and procedures which can be checked in.
Do I need to create an SQL database project and check it in?
If yes, is there an easy way to move the existing tables and procedures to the project?
Thanks
You can create a Database project using the SQL Server Data Tools (SSDT).
This project helps you in bringing tables, views, stored procedures and permissions under version control. After creating a new, empty database project you can choose to import the schema from an existing database. After importing the project you can make your changes directly in Visual Studio in the Database project and then update your localdb or the other way around.
[
Importing an existing schema is only possible when your Database project is empty. After an initial import, you need to use Schema Compare to import further changes from your database into your project.

update script when comparing Visual studio database project to schema file

I have created a database schema file of a customers database. I want to compare this schema file to my database project i Visual Studio 2010 to be able to script the schema changes that needs to be done to the customer database in connection to the upgrade of our client program.
For filesize matters I want to use this schema file (23MB) rather than getting a full database copy (1352 MB when zipped) from the customer.
I have no problem comparing the Visual Studio project to the schema file (no error messages or warnings) but I find no means to get the resulting update script. The error I am getting when pressing "Refresh update script" is: "you cannot write updates to the target when you compare the specified types of schema models". All export options are disabled.
Of course I understand that I can't write updates to the database schema but that is not my intention - I want to run the update script on the database at our customers server.
Is there any way I can get out the update script?
Thanks!
I solved it by taking a few extra turns:
I created an empty database on our local sql-server.
I compared the schema from our customers database with the empty database as target in Visual Studio and updated the empty database with the change script created by Visual Studio.
I compared the updated database with the new database schema from TFS.
The new change script I got from Visual Studio was deployed to our customers database.
Hope this helps someone, at least I learnt from it (and will hopefully remember this until the next release).

VB.NET - Local database (SQL Server Compact 3.5 database) data gone after update?

I have created an application in VB.NET (using Microsoft Visual Basic 2010 Express) with a local database (SQL Server Compact 3.5 database) to store data.
I have installed this on the users computer, and added a "search online for updates" functionallity (which can be selected when publishing)
Now i have noticed, that sometimes when i upload a new version, the data from the database gets cleared. (possibly when i opened the dtb while developing)
This is offcourse not how i want the system to behave, and the data should always remain on the users computer.
In 'Application Files' the database file (*.sdf) is currently set to 'Data File (Auto)', but i'm unsure of the exact way this works.
Could anyone help me to understand how all of this works, and tell me how i can be sure that the data in the users database will remain, even after an update?
If there is no solution to ensure this, is there a way to safely backup the data and reload it?
Thanks in advance!!
Basically, the click one install overwrites everything in the program folder that is included in your publish. So if you include the .sdf then it will overwrite it when the installer is executed. What you need to do is select "exclude" on the sdf instead. This will keep the database in its previous state.
So my recommendation would be to have 2 different publishes. One that you create that contains the .sdf which is only used on first time installation, and then in all the update ones you exclude it.
To perform updates on your tables you would have to write the SQL for it in your software. Basically do a check on all tables to see that they have the proper setup on startup. If they don't then you add the missing columns.
Hope this helps.

Backup only new or edited records

I have built a SQL Server Express database that is going to be housed on an external hd. I need to be able to add/update data on the database that is on my system, as well as other systems and then only backup or transfer data that has been added or edited to the external hard drive. What is the best way to accomplish this?
You would probably use replication for this but as you're using SQL Server express this isn't an option.
You'll need some sort of mechanism to determine what has changed between backups. So each table will need a timestamp or last updated date time column that's updated every time a record is inserted or updated. It's probably easier to update this column from a trigger rather than from your application.
Once you know which records are inserted or updated then it's just a matter of searching for these from the last time the action was performed.
An alternative is to add a bit column which is updated but this seems less flexible.
Sherry, please explain the application and what the rationale is for your design. The database does not have any mechanism to do this. You'll have to track changes yourself, and then do whatever you need to do. SQL Server 2008 has a change tracking feature built in, but I don't think that will help you with Express.
Also, take a look at the Sync Framework. Adding this into your platform is a major payload, but if keeping data in sync is one of the main objectives of your app, it may pay off for you.
In an application
If you are doing this from an application, every time a row is updated or inserted - modify a bit/bool column called dirty and set to true. When you select the rows to be exported, then select only columns that have dirty set to true. After exporting, set all dirty columns to false.
Outside an application
DTS Wizard
If you are doing this outside of an application, then run this at the Command-Line:
Run "C:\Program Files\Microsoft SQL Server\90\DTS\Binn\DTSWizard.exe"
This article explains how to get the DTS Wizard (it is not included as default).
It is included in the SQL Server
Express Edition Toolkit – and only
that. It you have installed another
version of SSE, it works fine to
install this package afterwards
without uninstalling the others. Get
it here:
http://go.microsoft.com/fwlink/?LinkId=65111
The DTS Wizard is included in the
option “Business Intelligence
Development Studio” so be sure to
select that for install
If you have installed another version
of SSE, the installer might report
that there is nothing to install.
Override this by checking the checkbox
that displays the version number (in
the installer wizard)
After install has finished, the DTS
Wizard is available at
c:\\Microsoft SQL
Server\90\DTS\Binn\dtswizard.exe you
might want to make a shortcut, or even
include it on the tools menu of SQL
Studio.
bcp Utility
The bcp utility bulk copies data between an instance of Microsoft SQL Server and a data > file in a user-specified format. The bcp utility can be used to import large numbers of > new rows into SQL Server tables or to export data out of tables into data files. Except > when used with the queryout option, the utility requires no knowledge of Transact-SQL.
To import data into a table, you must either use a format file created for that table or > understand the structure of the table and the types of data that are valid for its
columns.