Solved

How to create a database in a different location

Posted on 2002-07-27
9
167 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

719 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