Transfer an SQL database?
-
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
-
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
Q1: What was the error message when you tried to attach it to the SQL Server on the other machine? Q2: At a quick glance the line with the ExecuteNonQuery() is commented out. Also, I cannot find the EMPTY keywork in the Transact-SQL reference. Are you sure you are using the right command? I would have used DELETE.
Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!