Showing posts with label sqlexpress. Show all posts
Showing posts with label sqlexpress. Show all posts

Sunday, March 25, 2012

Cleaning up data files when removing instance (integr. inst.)

Hi everyone,

I'm trying to integrate SQLEXPRESS in a custom application ("the app"). On installation, a new instance ("myNewInstance") is created, and a new DB ("myDB") is created on that instance.

Upon de-installation of "the app", I remove the new instance. To that end, I'm calling the SQLEXPRESS setup like this:

Code Snippet

setup.exe /qb REMOVE=SQL_Engine INSTANCENAME=myNewInstance


The Problem: While the service and the instance are removed, the instance's data directory is not, and the DB Datafiles are still there. Now if I reinstall the app (re-creating myNewInstance), it uses the same directory structure, and when I try to re-create the DB, I get the following error message:

Code Snippet

Msg 5170, Level 16, State 1, Line 1
Cannot create file '[...]\MSSQL.2\MSSQL\DATA\myDB.mdf' because it already exists. Change the file path or the file name, and retry the operation.


So here's the Question: is there
a) any way to tell setup.exe to completely remove the datafiles when uninstalling the instance, or
b) any way to tell TSQL to overwrite the old datafiles if they exist?

Thanks in advance,
Thorsten

hi Thorsten,

AFAIK, the setup/uninstall wizard does not provide a way to delete user's database, and this usually is a good thing as user's databases are actually the "real important things" to be preserved.. a setup option, SAVESYSDB=0/1 extend that feature to system databases as well, that are usually deleted in normal uninstall situations.. but "the contrary" is not available... but you can probably add a custom task to your uninstall (I do think via ORCA) to delete all "orphaned" remaining files...

regards

Friday, February 10, 2012

check sql server edition

is there a way to get the edition(e.g. sqlexpress,enterprise etc...) of an installed sql server instance in your local machine programatically?

Code Snippet

select serverproperty('Edition')

HTH!|||alright! thanks man! Smile but is there some other way... without executing a query from the server?|||

I guess another way would be to query the registry for the information. Looking around there appears to be that information in the registry key for SQL2005:


HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Setup\Edition

HTH!

|||

i've checked my registry... but it seems its not correct to read the registry when checking an installed sqlserver edition... it's not accurate..my machine have some previous sqlserver installations before and my registry looks like this..

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Setup\Edition\Developer Edition

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.2\Setup\Edition\DeveloperEdition

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.3\Setup\Edition\Express Edition

...

...

......

.........

............

...............

but there is only one developer edition instance installed in my machine...

|||

Hi,

I guess your registry showing is correct.

During SQL Server Setup, an instance ID is generated for each server component. The server components in this SQL Server release are the Database Engine, Analysis Services, and Reporting Services. The instance ID is in the format MSSQL.n, where n is the ordinal number of the component being installed. The instance ID is used in the file directory and the registry root.

The first instance ID generated is MSSQL.1; ID numbers are incremented for additional instances as MSSQL.2, MSSQL.3, and so on. If gaps occur in the ID sequence due to uninstalls, ID numbers are not generated to fill them. The most recently installed instance always has the highest instance ID number.

Server components are installed in directories with the format <instanceID>\<component name>. For example, a default or named instance with the Database Engine, Analysis Services, and Reporting Services would have the following default directories:

<Program Files>\Microsoft SQL Server\MSSQL.1\MSSQL\ for the Database Engine

<Program Files>\Microsoft SQL Server\MSSQL.2\OLAP\ for Analysis Services

<Program Files>\Microsoft SQL Server\MSSQL.3\RS\ for Reporting Services