Solved

How to create a database in a different location

Posted on 2002-07-27
9
164 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
ID: 7181788
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
ID: 7181858
Any second opinion?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7181969
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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 3

Expert Comment

by:RodStephens
ID: 7181999
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
 
LVL 5

Expert Comment

by:jayeshshah
ID: 7183185
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
ID: 7184674
dear emor

im using VB

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

0
 
LVL 70

Expert Comment

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

Author Comment

by:ackid32
ID: 7187701
give me the VB Code pls
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 200 total points
ID: 7187721
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

777 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