I am using " Microsoft.SqlServer.Management.Smo". I am trying to attach a database using the AttachDatabse method in it. but it is not working for me.
I am pasting my code as follows...tell me the problem or the right way to do it...
SqlConnection Connection =newSqlConnection("Data Source=SHEBZ; User ID=sa; Password=sa");
Microsoft.SqlServer.Management.Common.ServerConnection con =new Microsoft.SqlServer.Management.Common.ServerConnection(Connection);Server ser =newServer("SHEBZ");ser.ConnectionContext.Connect();
System.Collections.Specialized.StringCollection File =new System.Collections.Specialized.StringCollection();
File.Add(@."D:\Project-Parts\MasterPageOffice\Uploads\Db3");try
{
ser.AttachDatabase("Db3", File);}
catch (Exception ex){
Label1.Text ="ERROR: " + ex.Message.ToString();}
Hi,
What you are using is Server.AttachDatabase method, try to follow the sample below.
Datastr = "C:\Program Files\Microsoft SQL Server"Datastr = datastr + "\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf"Logstr = "C:\Program Files\Microsoft SQL Server"Logstr = datastr + "\MSSQL.1\MSSQL\Data\AdventureWorks_Log.ldf"
StringCollection sc;sc = new StringCollection();sc.Add(datastr);sc.Add(logstr);srv.AttachDatabase("AdventureWorks", sc, owner, AttachOptions.None);
Thanks.|||
I know this code...it is for detaching and attaching the databse to a SQL Server 2005 or high..... if you try to use this code for SQL Server 2000 you will get the same exception that this property or method can be used with Sql Server 2005 or high... i want a solution for 2000...
No comments:
Post a Comment