Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to create a database in a different location

Posted on 2002-07-27
9
Medium Priority
?
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 800 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

598 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