Solved

How to create a database in a different location

Posted on 2002-07-27
9
162 Views
Last Modified: 2010-05-02
How to create a database in a different location in SQL-Server.
Like doing
 createdatabase("c:\bla\abc\xyz.mdb")

i want my database is stored where i want in sql-server.
0
Comment
Question by:ackid32
9 Comments
 
LVL 1

Expert Comment

by:Shivshankar
Comment Utility
SQL Server is not like an access database. You cannot specify a path for a database like this.

Yes, if you have sa rights, then you can create database. But, creating databases dynamically like this in an application is not generally recommended. You must understand that SQL Server has to build a host of tables (sys*) for any given database and statistics and so many stuff.

Best Regards.
0
 

Author Comment

by:ackid32
Comment Utility
Any second opinion?
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
You can use the FileName parameter. Check this sample:

USE master
GO
CREATE DATABASE Sales
ON
( NAME = Sales_dat,
   FILENAME = 'c:\program files\microsoft sql server\mssql\data\saledat.mdf',
   SIZE = 10,
   MAXSIZE = 50,
   FILEGROWTH = 5 )
LOG ON
( NAME = 'Sales_log',
   FILENAME = 'c:\program files\microsoft sql server\mssql\data\salelog.ldf',
   SIZE = 5MB,
   MAXSIZE = 25MB,
   FILEGROWTH = 5MB )
GO
0
 
LVL 3

Expert Comment

by:RodStephens
Comment Utility
Note that the previous solution (which looks correct) requires that you be already connected to the database server. The data and log information is stored in the indicated files, but it cannot work without the server, too. It's not like in Access where you can simply copy the files to another computer and have them work.

My book "Visual Basic .NET Database Programming" (http://www.vb-helper.com/vbdb.htm) shows how to build SQL Server databases, make a program that can execute this kind of script, and a lot of other stuff.

As an aside, also note that you can use MSDE instead of SQL Server. It has roughly the same features but is free. There's an intro at: http://www.informit.com/content/index.asp?product_id={D31B236D-00C1-4A5A-8832-BC9A68E9D5B8}
0
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

 
LVL 5

Expert Comment

by:jayeshshah
Comment Utility
make a connection to that SQL server where you want to make your database & then using the connection statement execute the following statement

g_Connection.execute "Create database databasename"
0
 

Author Comment

by:ackid32
Comment Utility
dear emor

im using VB

and for that pls explain the code (where i put your code?)

0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
Create an ADO connection to the Master database. Then use the Execute method to run the CREATE DATABASE statement.
0
 

Author Comment

by:ackid32
Comment Utility
give me the VB Code pls
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 200 total points
Comment Utility
dim oConn as new adodb.connection

oConn.Open "Provider=sqloledb;" & _
           "Data Source=myServerName;" & _
           "Initial Catalog=Master;" & _
           "Integrated Security=SSPI"
oConn.execute "CREATE DATABASE Sales " & _
     "ON  " & _
     "( NAME = Sales_dat, " & _
     "  FILENAME = 'c:\program files\microsoft sql server\mssql\data\saledat.mdf', " & _
     "  SIZE = 10, " & _
     "  MAXSIZE = 50, " & _
     "  FILEGROWTH = 5 ) " & _
     "LOG ON " & _
     "( NAME = 'Sales_log', " & _
     "  FILENAME = 'c:\program files\microsoft sql server\mssql\data\salelog.ldf', " & _
     "  SIZE = 5MB, " & _
     "  MAXSIZE = 25MB, " & _
     "  FILEGROWTH = 5MB ) "
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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

11 Experts available now in Live!

Get 1:1 Help Now