[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Set up  dynamically   database

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

how to do it  ?
0
Comment
Question by:Yampolka
  • 3
4 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 2000 total points
ID: 40262370
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;
GO
CREATE DATABASE Sales
ON 
( 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 ) ;
GO

Open in new window

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

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.:
Provider=SQLNCLI11;Server=myServerAddress;Database=myDataBase;Uid=myUsername;
Pwd=myPassword;

Open in new window

0
 

Author Comment

by:Yampolka
ID: 40309147
When I do it from SQL Managemet Studio - I am Fine
But when I do it from asp.net application ,
 I have  CREATE DATABASE permission denied in database 'master'.
0
 

Assisted Solution

by:Yampolka
Yampolka earned 0 total points
ID: 40442643
This could be resolved with  Server Authentication   and admin login
0
 

Author Closing Comment

by:Yampolka
ID: 40451929
Solution could be implemented if
1) DB install server with mixed mode
2) You know Admin Password
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

872 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