Set up  dynamically   database

Posted on 2014-08-14
Last Modified: 2014-11-19
I have project . What I need
1) Create Data Base dynamically from ASP.NET  application
2) generate connection string  for this database

how to do it  ?
Question by:Yampolka
    LVL 24

    Accepted Solution

    One of the ways to do so is by using T-SQL. You need to connect to the server in the first place though. Connect to the server as an admin (use 'sa' account, or any other DB Admin account) and connect to the master database. Then, just use CREATE DATABASE command. Please note however, that you need to have a basic idea of the DB server Disk Drives and folders. Perhaps your DB admin has specified that the default data location is for example D:\Data, and the Transaction Log location is D:\Logs. The syntax may look complicated by basically all you need is this:
    USE master;
    ( NAME = Sales_dat,
        FILENAME = 'D:\DATA\saledat.mdf',
        SIZE = 10,
        MAXSIZE = 50,
        FILEGROWTH = 5 )
    LOG ON
    ( NAME = Sales_log,
        FILENAME = 'D:\Logs\salelog.ldf',
        SIZE = 5MB,
        MAXSIZE = 25MB,
        FILEGROWTH = 5MB ) ;

    Open in new window

    In fact, according to the link above you can even create the database like this:
    USE master;

    Open in new window

    The following example creates the database mytest and creates a corresponding primary and transaction log file. Because the statement has no <filespec> items, the primary database file is the size of the model database primary file. The transaction log is set to the larger of these values: 512KB or 25% the size of the primary data file. Because MAXSIZE is not specified, the files can grow to fill all available disk space.
    When the database is created you will need to disconnect from the master database. You will have to reconnect to the newly created database. The connection string to this new database will be the same, except for the "Database=" parameter, i.e.:

    Open in new window


    Author Comment

    When I do it from SQL Managemet Studio - I am Fine
    But when I do it from application ,
     I have  CREATE DATABASE permission denied in database 'master'.

    Assisted Solution

    This could be resolved with  Server Authentication   and admin login

    Author Closing Comment

    Solution could be implemented if
    1) DB install server with mixed mode
    2) You know Admin Password

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now