Showing posts from April, 2010


Create a SQL Server Database by using SMOIn this small tutorial I will show you how to create a database with SMO and C# in Visual Studio 2008. I will use a Console application.
Prerequisites:SQL Server 2005 is installedVisual Studio 2008 is installedCodeAssembliesYour C# project must reference:
SystemSystem.DataMicrososft.SqlServer.ConnectionInfoMicrososft.SqlServer.Management.Sdk.SfcMicrososft.SqlServer.SmoNamespacesThe source class file must use:
SystemSystem.Data.SqlClientMicrososft.SqlServer.Management.CommonMicrososft.SqlServer.Management.Smoclass ConsoleSmo {   public static Main()   {     string connLocal = "Data Source=(local); Integrated Security=SSPI;"SqlConnection connection = newSqlConnection(connLocal);     Server server = newServer(newServerConnection(connection));     Database db = newDatabase(server, “TestDb”);     db.Create();     connection.Close();   } } ExplanationsThis code opens the connection to the server and produces the Server object. Next, it creates…