Showing posts with label copy. Show all posts
Showing posts with label copy. Show all posts

Thursday, March 29, 2012

Attach Db With Same Files As Existing Db

In SQL Server 2000, I would like to attach a Database that is the file of the Database on another system. I made a copy of my Client's Database at his site. Now I would like to attach it to my server and then copy the data from my Client's DB to mine.

The only problem is they have the same file names, so when I try to attach the copy I get an error message. Is there any way to change the name of the data file and log file that a database points to so that I can attach it to my Server?

Thanks in advance for your help!Look up RESTORE DATABASE in Books Online. You need to use the WITH MOVE option.

RESTORE DATABASE database
WITH
MOVE 'logical data file' TO 'somenewfile.mdf',
MOVE 'logical log file' TO 'somenewfile.ldf'

You can find the name of the files by using: RESTORE FILELISTONLY FROM DISK = 'file.bak'

Tuesday, March 27, 2012

Attach db from installer (only read mode)

Hi,

I have made setup of my program,

I need to attach a db to the server. To do this:

- Copy mdf and ldf files into default data folder of instance of sqlexpress

- run scrip from custom action in the installer that:

a. attach the db

b. create login

c. create user for login in db

There is a problem...I run script slq file by sqlcmd and launch it from a c# process.

The rusult is that the db was attacched but in only read mode, and the point c not work.

If I execute manually the same script sql with sqlcmd in dos window, it work without problem in all point: a,b and c

What are the reason of this?

I think that start process in c# not work correctly....this is the code:

process = new Process();

process.StartInfo.FileName = "sqlcmd.exe";

process.StartInfo.Arguments = commandLine;

process.Start();

process.WaitForExit();

help me, plese!

thanks in advance

andrea

SInce you have posted this in Express forum, i strongly feel that you should use SQL Server Express User Instance feature. Its nothing but Embedded Database.

Refer this.

http://blogs.msdn.com/sqlexpress/archive/2006/11/22/connecting-to-sql-express-user-instances-in-management-studio.aspx

Madhu

Attach db ... but changing its db name

I've a copy of my customer db detached from its server.
I need to import into my SQL to compare data and structure with my
own to release him some new feature. Problem is how to import it.
If I simple attach db, SQL server mustn't do it, trapping duplicate
db name or something else (I wish is so and not overwrite db).
If I detach my db, and attach customer db ... I must rename db ...
but how? until today I never read of some function that rename
db ...
Can anyone give me more info please?
--
Sincerely
Andrea Morowhile attaching db with sp_attach_db you can specify the required name of
the database to be. If you want to rename the existing database you can make
use of system stored proceudre sp_renamedb
--
-Vishal
Andrea Moro <moroandreaET@.tiscalinet.it> wrote in message
news:#kH0j9LcDHA.1204@.TK2MSFTNGP12.phx.gbl...
> I've a copy of my customer db detached from its server.
> I need to import into my SQL to compare data and structure with my
> own to release him some new feature. Problem is how to import it.
> If I simple attach db, SQL server mustn't do it, trapping duplicate
> db name or something else (I wish is so and not overwrite db).
> If I detach my db, and attach customer db ... I must rename db ...
> but how? until today I never read of some function that rename
> db ...
> Can anyone give me more info please?
> --
> Sincerely
> Andrea Moro
>sql

Attach database in sql 2005

I detached a db to copy it and to my surprise i cant reattach it the same way i detached ... How do i do this?use master
go
sp_attach_db 'CompanyTbl','C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\DMS_Data.mdf',
'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\DMS_Log.ldf'
go