Transfer an SQL database?

C

Cem Louis

Hi,

Q1: How can I transfer an SQL database manually? I have a database
which is named mydb, I looked at the harddrive and found it on
"C:\Program Files\Microsoft SQL Server\MSSQL\Data" there is 2 file one
of them is mydb.mdf and the lof file of that. I copied these on
another machine on the same path but couldn't make it to work???

Q2: I used the below code to EMPTY a table which is named people but
it is not working???:

SqlConnection mySqlConnection4 = new SqlConnection("Initial
Catalog=mydb;Data Source=" + comboBox1.SelectedItem.ToString() +
";Integrated Security=SSPI;");
mySqlConnection4.Open();
SqlCommand mySqlCommand4 = mySqlConnection4.CreateCommand();
SqlTransaction myTrans;
myTrans = mySqlConnection4.BeginTransaction(IsolationLevel.ReadCommitted,"SampleTransaction");
mySqlCommand4.Connection = mySqlConnection4;
mySqlCommand4.Transaction = myTrans;
mySqlCommand4.CommandText = "EMPTY people" ;
//mySqlCommand4.ExecuteNonQuery();
myTrans.Commit();
mySqlConnection4.Close();


Anyway What is the problem???

Any help would be greatly appreciated...
Cem Louis
 
J

Jeff Louie

Cem...
Before you transfer the files you need to halt the database and detach
it using
say OSQL
sp_detach_db 'mydb','true'
Once you have transfered the mdf and ldf files you need to attach them
using
say OSQL
start-->run
OSQL /U [mypassword] /P /S [myservername]
sp_attach_db 'mydb','pathtomdf','pathtoldf'
go
exit

DELETE FROM // be careful!

Regards,
Jeff
Q1: How can I transfer an SQL database manually?
mySqlCommand4.CommandText = "EMPTY people"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top