2

I am trying to run the below code. It works for me but not for at least some of my users it doesn't work. It doesn't seem to error just no actually remove the DB's.

string sqlConnectionString=@"Data Source=.\SQLEXPRESS;Initial Catalog=master;Integrated Security=True";
var theSQL="DROP DATABASE DBName1, DBName2, DBName3, DBName4";
SqlConnection conn=new SqlConnection(sqlConnectionString);
Server server=new Server(new ServerConnection(conn));

server.ConnectionContext.ExecuteNonQuery(theSQL);

Alternatively, what I really need is to remove the existing Replication Sets on those DB's so that I can setup the new ones. We moved to a new SQL Server but the database names are the same.

The subscription could not be initialized using an initial snapshot because one or more tables in the subscription belong to another publication, and therefore cannot be dropped. Consider initializing the subscription manually without using a snapshot.

Error they receive, though this would be after the above was supposed to run as this is during the Sync that happens next.

  • Could you define "doesn't work?" Post the actual error they receive. It could be lack of permissions. There could be an active connection to the database. – billinkc Aug 20 '12 at 0:39
  • thanks, added the exception though I noted this is after the scripts. – Refracted Paladin Aug 20 '12 at 1:10
1

Depending on whether or not these are subscriptions or the published database you are going to need to drop the replication data.

MS Published a handy doc with example scripts here http://support.microsoft.com/kb/324401

This one is a general tool to clear out what you need

sp_removedbreplication '<Database name>'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.