sharing about .NET and technology RSS 2.0
# Wednesday, August 06, 2008

SQL Server 2008 is now available on MSDN and TechNet, see the announcement here. To have an overview of the new features, you can have a look here and you may download the SQL Server 2008 Books Online. Apparently has SQL Server 2008 powershell support!

Wednesday, August 06, 2008 9:40:44 PM (Romance Daylight Time, UTC+02:00) -  # -  Comments [1] -
Links | SQL Server
# Monday, December 31, 2007

SMO (SQL Server Management Objects) is a .NET based object library for programming all aspects of managing Microsoft SQL Server. Replication Management Objects (RMO) is another library that encapsulates SQL Server replication management.

SMO assemblies are shipped with SQL Server 2005 and can be used to connect with SQL Server 7, 2000 or 2005. The assemblies are located in the following folder C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies.

  • Microsoft.SqlServer.Smo.dll
  • Microsoft.SqlServer.ConnectionInfo.dll
  • Microsoft.SqlServer.SmoEnum.dll
  • Microsoft.SqlServer.SqlEnum.dll

With SMO you can do all kind of management on a SQL Server, namely: tables, columns, indexes, stored procedures, service broker, backup and restore, managing users/roles and logins, scheduling, etc. Here you can find some specific tasks that can be done with SMO.

Below you find an example how you can create a table with SMO:

using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;

public class Sample
{
    public void Create(string connectionstring)
    { 
        SqlConnection connection = new SqlConnection(connectionstring);
        Server server = new Server(new ServerConnection(connection));
        
        Database database = server.Databases["MyDatabase"];
        
        // Create table, called Customer
        Table table = new Table(database, "Customer");
        
        // Add 'ID' column which is the primary key
        Column idColumn = new Column(table, "ID");
        idColumn.DataType = DataType.Int;
        idColumn.Identity = true;
        idColumn.IdentitySeed = 1;
        idColumn.IdentityIncrement = 1;
        
        // Create a primary key index
        Index index = new Index(table, string.Format("PK_{0}", table.Name));
        index.IndexKeyType = IndexKeyType.DriPrimaryKey;
        index.IndexedColumns.Add(new IndexedColumn(index, "ID"));
        table.Indexes.Add(index);                        
        
        // Add 'Name' column
        Column nameColumn = new Column(table, "Name");
        nameColumn.DataType = DataType.VarChar(50);
        
        // Add colums to table
        table.Columns.Add(idColumn);
        table.Columns.Add(nameColumn);
        
        table.Create();
    }
}
Monday, December 31, 2007 3:04:11 AM (Romance Standard Time, UTC+01:00) -  # -  Comments [2] -
.NET | Database | SQL Server
Navigation
Archive
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Christoph De Baene
Sign In
Statistics
Total Posts: 176
This Year: 2
This Month: 0
This Week: 0
Comments: 283
All Content © 2010, Christoph De Baene
DasBlog theme 'Business' created by Christoph De Baene