/* There are 3 dlls to add to the references. They are commented in the using statements */ using System; using System.Collections.Generic; using System.Linq; using System.Text; // microsoft.sqlserver.smo.dll using Microsoft.SqlServer.Management.Smo; // microsoft.sqlserver.connectioninfo.dll // Microsoft.SqlServer.Management.Sdk.Sfc.dll using Microsoft.SqlServer.Management.Common; namespace GregoryAdam.Test { public class SqlServerSmoTest { public static void ConnectTest() { Server server = new Server(); server.ConnectionContext.ServerInstance = @"ComputerName\SQLEXPRESS"; server.ConnectionContext.LoginSecure = false; server.ConnectionContext.Login = "Id"; server.ConnectionContext.Password = "passwd"; Console.WriteLine("InstanceName {0}", server.InstanceName); foreach (Database db in server.Databases) { Console.WriteLine(" Name: {0} #Connections={1}", db.Name, db.ActiveConnections); foreach (FileGroup fg in db.FileGroups) { foreach (DataFile df in fg.Files) { Console.WriteLine(" File: {0} ", df.FileName); } } Console.WriteLine(); } } } }