Transfer an SQL database?

  • Thread starter Thread starter Cem Louis
  • Start date Start date
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
 
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"
 
Back
Top