SMO connection

This sample is written in C# and use SQL Server 2005 beta 2 and a beta version of the .Net Framework 2.0. It show how, with SMO you can Connect to SQL Server 2005

In order to connect to SQL Server using SMO you have to reference the following namespace (and the corresponding assembly):

using

Microsoft.SqlServer.Management.Smo;

using

Microsoft.SqlServer.Management.Smo.Agent;

using

Microsoft.SqlServer.Management.Common;

 

1) The following code allow you to connect with the intergrated security :

ServerConnection conn;

Server sqlserver;

conn =

new ServerConnection();

conn.ServerInstance = "My Server"

conn.LoginSecure = true;

conn.Connect();

sqlserver =

new Server(conn);

The object sqlserver is the object on with youe are going to work on each SMO project (to have to list of database for example).

2) The following code allow you to connect to SQL Server with the SQL Server authentification :

ServerConnection conn;

Server sqlserver;

conn =

new ServerConnection();

conn.ServerInstance = "My Server";

conn.Login = "My login";

conn.Password = "My Password";

conn.LoginSecure = true;

conn.Connect();

sqlserver =

new Server(conn);