can not copy database files
-
hi.i want copy database files.when i do detach database throw exeption.i search web and find things.but i cant drive result. please help me.thanks.
string ConnStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mydb.mdf"
+";Integrated Security=True;User Instance=True";
SqlConnection mycon = new SqlConnection(ConnStr);
SqlCommand mycom = new SqlCommand("sp_detach_db @d=db_name()", mycon);
mycon.Open();
mycom.ExecuteScalar();
mycon.Close(); -
hi.i want copy database files.when i do detach database throw exeption.i search web and find things.but i cant drive result. please help me.thanks.
string ConnStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mydb.mdf"
+";Integrated Security=True;User Instance=True";
SqlConnection mycon = new SqlConnection(ConnStr);
SqlCommand mycom = new SqlCommand("sp_detach_db @d=db_name()", mycon);
mycon.Open();
mycom.ExecuteScalar();
mycon.Close();Try these:
string ConnStr = @"Data Source=.\SQLEXPRESS;Database=Master;Integrated Security=True";
SqlConnection mycon = new SqlConnection(ConnStr);
SqlCommand mycom = new SqlCommand("sp_detach_db", mycon);
mycom.CommandType= CommandType .StoredProcedure ;
mycom.Parameters.Add(new SqlParameter("@dbname", SqlDbType.NVarChar,50));
mycom.Parameters["@dbname"].Value = "mydb";
mycon.Open();
mycom.ExecuteScalar();
mycon.Close(); -
hi.i want copy database files.when i do detach database throw exeption.i search web and find things.but i cant drive result. please help me.thanks.
string ConnStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mydb.mdf"
+";Integrated Security=True;User Instance=True";
SqlConnection mycon = new SqlConnection(ConnStr);
SqlCommand mycom = new SqlCommand("sp_detach_db @d=db_name()", mycon);
mycon.Open();
mycom.ExecuteScalar();
mycon.Close();What was not pointed out is that you cannot detach a database the your using. You have to execute the detach sp connected to the master db in SQL Server.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...