Monday, March 19, 2012

Can I Attach a database with SMO?

I just developed a solution locally, I would like my installer to attach a database on the CD and then modify the web.config, I am interested in learning how to attach it programatically with SMO?

ThankHere is a very simple example:

using System.Collections.Specialized;

using Microsoft.SqlServer.Management.Common;

using Microsoft.SqlServer.Management.Smo;

Server svr;

StringCollection sc;

svr = new Server();

sc = new StringCollection();

sc.Add(@."c:\test.mdf");

svr.AttachDatabase("test", sc);

|||Thank you very much. I love ya.. just kidding.

No comments:

Post a Comment