Solved

How to create a database in a different location

Posted on 2002-07-27
9
163 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 69

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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 69

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 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

920 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

12 Experts available now in Live!

Get 1:1 Help Now