Questions tagged [smo]

SQL Server Management Objects (SMO) are .NET objects for management of Microsoft SQL Server. The namespace is "Microsoft.SqlServer.Management.Smo".

The Microsoft.SqlServer.Management.Smo namespace contains classes that represent the core SQL Server Database Engine objects. These include instances, databases, tables, stored procedures, and views.

The Microsoft.SqlServer.Management.Smo namespace contains the instance object classes that represent SQL Server Database Engine objects and some utility classes that represent specific tasks, such as scripting. When a connection to the instance of the SQL Server Database Engine has been established by using a Server object variable, objects on the instance can be accessed by using the SMO instance objects. For example, you can use the Database object to access databases on the connected instance of SQL Server Database Engine. All the instance classes are related to the Server class in the object hierarchy. Utility classes exist outside of the Server class object hierarchy and represent specific tasks, such as backup or scripting.

Most of the classes Microsoft.SqlServer.Management.Smo namespace resides in the Microsoft.SqlServer.Smo.dll and Microsoft.SqlServer.SmoExtended.dll files. Additionally, some of the enumeration classes are in the Microsoft.SqlServer.SqlEnum.dll and Microsoft.SqlServer.SmoEnum.dll assembly files. You will have to import all four files to access all of the classes in the Microsoft.SqlServer.Management.Smo namespace.

src=http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.aspx

810 questions
11
votes
1 answer

C# SMO Database do not log creation

I have an integration test that creates a database of type Microsoft.SqlServer.Management.Smo.Database: var defaultConnectionConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString(); var sqlConnection = new…
Scotty H
  • 6,432
  • 6
  • 41
  • 94
11
votes
3 answers

Inconsistent default constraints from SQL Server Management Objects (SMO)

I have program that generates DDL scripts for a Microsoft SQL Server database using SQL Server Management Objects (SMO). However, depending on the server and database, I receive inconsistent output of default constraints for tables. Sometimes they…
Sybeus
  • 1,169
  • 11
  • 18
9
votes
4 answers

Can't immediately connect to newly-created SQL Server database

I'm creating a database using SQL Server Management Objects. I wrote the following method to generate a database: public static void CreateClientDatabase(string serverName, string databaseName) { using (var connection = new…
GWB
  • 2,575
  • 2
  • 23
  • 28
9
votes
2 answers

Error restoring database backup to new database with smo and powershell

Taking a database backup from another server I'm trying to restore to sqlexpress on the localhost. This restore will work via the gui but I'm having issues restoring it with powershell. I get the following error message: Exception calling…
sclarson
  • 4,362
  • 3
  • 32
  • 44
9
votes
2 answers

SMO: restoring to a different DB, why db is null?

This is my problem, I have a restore function in C# guided by this answers: SMO: restoring to a different DB But when the program tries to execute this code db.SetOnline(); it throws an exception: Object reference not set to an instance of an…
9
votes
2 answers

Display Progress while Restoring Database with PowerShell and SMO

I have a script for restoring a database with PowerShell and SMO. Now I know that I can pass a event handler into PercentComplete on the restore object and get the progress of the restore as it happens. The problem is I don't know how to create a…
Lukasz
  • 8,710
  • 12
  • 44
  • 72
9
votes
3 answers

Change logical database name with SMO

How can I change the logical database name when restoring a database with SMO? /Viktor
Viktor
  • 476
  • 3
  • 16
9
votes
4 answers

How to generate sql scripts using SMO scripter

My database has tables, views and all. And I need a way to generate SQL script for all the DDL in an automated manner. No need for data. There are FK constraints so table creation scripts should be ordered properly. Some views use another view, so…
kennethc
  • 814
  • 1
  • 10
  • 26
9
votes
2 answers

Drop all active database connections failed for Server when executing KillAllProcesses

I need to perform a database restore from my application. Before doing this, I want to kill all processes as follows: private void KillAllProcessesOnSMARTDatabases(Server targetServer) { targetServer.KillAllProcesses(SMART_DB); …
laconicdev
  • 6,360
  • 11
  • 63
  • 89
9
votes
3 answers

How to set CommandTimeout

I am using Microsoft.SqlServer.Management.Smo. My Code: Server server = new Server(new ServerConnection( new SqlConnection(ConnectionString)); server.ConnectionContext.ExecuteNonQuery(script); I want to set CommandTimeout for it like we do with…
Dr. Rajesh Rolen
  • 14,029
  • 41
  • 106
  • 178
8
votes
5 answers

Programmatically detect SQL Server Edition

I'm using C# with SMO and attempting to detect what edition of SQL Server (e.g., enterprise, standard) I'm connecting to. I know how to get the version information, but that only tells me what version of SQL Server (e.g., SQL Server 2008 vs SQL…
reustmd
  • 3,513
  • 5
  • 30
  • 41
8
votes
4 answers

How to append to powershell Hashtable value?

I am interating through a list of Microsoft.SqlServer.Management.Smo.Server objects and adding them to a hashtable like so: $instances = Get-Content -Path .\Instances.txt $scripts = @{} foreach ($i in $instances) { $instance = New-Object…
Mark Allison
  • 6,838
  • 33
  • 102
  • 151
8
votes
3 answers

Cannot bind RelocateFile when using Restore-SqlDatabase cmdlet

I have SQL Server 2012 Developer installed on my machine. I also have the SQL Server 2014 management objects installed, too, which is probably the source of the problem. I'm writing a module to automate some common development tasks via Powershell.…
moribvndvs
  • 42,191
  • 11
  • 135
  • 149
8
votes
1 answer

Using LinqPad with SMO

I am trying to use the SMO for Sql Server 2008 R2 Standard, but I am running into an issue whenever I try to Dump an object. The relevant code: void Main() { var connectionString = @"Server=(local);Trusted_Connection=True;"; Server server =…
Dustin Kingen
  • 20,677
  • 7
  • 52
  • 92
8
votes
3 answers

Fixing Orphaned Users with SQL SMO?

Is there a way to fix an orphaned user in a SQL 2005/2008 database using SQL SMO? You can find orphaned users relatively easily by enumerating through the users and looking for an empty User.Login property: using…
Yoopergeek
  • 5,592
  • 3
  • 24
  • 29
1
2
3
53 54