Is it possible to set the database name in advance when deploying client database with an installer option?


We have a requirement from our clients to deploy the database and set the database name in advance when installating the SQL Express or MSDE with the auto-install option.


It is possible to create the database dynamically using SP_EXECUTESQL to build the SQL statements during runtime. You can then use EXECUTE to run the defined string, which is the option to create the database dynamically by using name the user inputs. The create database statement is constructed as follows:

declare @db  varchar(50)
select @db=’testdb’
select @db=’create database ‘ +@db
Execute (@db)

To accomplish this you could also use SMO (Server Management Objects) in SQL Server 2005 which is installed automatically with the Client Tools option selected in the installation program. The SMO files can be specifically added or removed from the installation by choosing the SDK branch of the Client Components option on the feature selection screen during setup. Similary in SQL Server 2000 you can use DMO (Distributed Management Objects), in SQL Server 2005 the DMO feature is installed as a legacy component. To install the Legacy Components feature, click Advanced on the Components to Install page during SQL Server Setup. Expand the Client Components feature and then select Legacy Components. Refer the following Books Online articles for further information on usage of SMO or DMO:

Database Class

How to: Create, Alter, and Remove a Database in Visual Basic .NET

Create database in sql server using with C#


Leave a comment

Your email address will not be published.