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
67
votes
9 answers

Programmatically retrieve SQL Server stored procedure source that is identical to the source returned by the SQL Server Management Studio gui?

Any pointers on how I can programmatically get exactly the identical stored procedure source from SQL Server 2005, as when I right-click on that stored procedure in SQL Server Management Studio and select modify? I'm trying using SMO, but there are…
DWright
  • 9,258
  • 4
  • 36
  • 53
51
votes
11 answers

Reference Microsoft.SqlServer.Smo.dll

I need to use Server class which is stored in Microsoft.SqlServer.Smo.dll I don't see this assembly in usual References dialog. I have found it at C:/Program Files/Microsoft SQL Server/100/SDK/Assemblies and try to reference from there but Visual…
SiberianGuy
  • 24,674
  • 56
  • 152
  • 266
23
votes
4 answers

Using SMO to copy a database and data

I am trying to make a copy of a database to a new database on the same server. The server is my local computer running SQL 2008 Express under Windows XP. Doing this should be quite easy using the SMO.Transfer class and it almost works! My code is…
Rune Grimstad
  • 35,612
  • 10
  • 61
  • 76
19
votes
7 answers

Is it possible to create a Database in SQL Server with powershell?

I am trying to create a empty database in SQL server using powershell and SMO but cannot seem to find a way of doing it. Is this possible? Connection script for sql server: [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO')…
ajack
  • 586
  • 1
  • 5
  • 13
19
votes
4 answers

How to use Powershell Where-Object like an IN statement

I have the following code which works: foreach ($db in $svr.Databases | where-object { $_.name -eq "testDB" -or $_.name -eq "master" -or $_.name -eq "model" -or $_.name -eq "msdb" } ) { write-output…
8kb
  • 10,956
  • 7
  • 38
  • 50
19
votes
3 answers

Can't find Microsoft.SqlServer.ConnectionInfo.dll assembly file?

I'm trying to dynamically get a databases Table structure using only C# code as follows: using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo; public class LoadStuff { ... public void LoadDatabase(string…
delete
18
votes
2 answers

How to set SMO ScriptingOptions to guarantee exact copy of table?

What I'm trying to do: Create an SQL script using C# to create an exact copy of an existing table. My Question: How would you define the options in scriptingOptions to insure that the resulting script would create a 100% exact copy of a table? …
sooprise
  • 22,657
  • 67
  • 188
  • 276
17
votes
7 answers

Could not load file or assembly microsoft.sqlserver.sqlclrprovider 13.100.0.0

I run my Winforms app using SQLServer assemblies Microsoft.SqlServer.ConnectionInfo (13.100.0.0) Microsoft.SqlServer.SMO(13.100.0.0) On the same machine SSMS 2016(Aug) is installed. And here SQL 2014 Dev Edition is installed too. WHen I run my app…
ZedZip
  • 5,794
  • 15
  • 66
  • 119
16
votes
3 answers

How to restore a database from C#

I have a SQL 2008 DB. I am running a form that backs that DB up, then tries to update it. If the update fails the idea is to restore that backup. Here is the code I am using to restore the backup. public void RestoreDatabase(String databaseName,…
Anthony D
  • 10,877
  • 11
  • 46
  • 67
15
votes
1 answer

ScriptingOptions sql smo does not support scripting data

I'm generating sql database script using c# code. following code works fine for create table but when I try to use scriptOptions.ScriptData = true; it is throwing following exception. An unhandled exception of type …
Neo
  • 15,491
  • 59
  • 215
  • 405
15
votes
1 answer

ServerConnection.Cancel method

The SqlCommand class has a Cancel method that, according to the documentation, allows one to cancel a command. I'm looking for an equivalent method for commands executed through the smo Server class. The ServerConnection class (connectioncontext…
Cristiano Sousa
  • 934
  • 1
  • 6
  • 31
15
votes
1 answer

smo restore database

I use SQL Server SMO to restore a .bak to a new database, but failed to work. sql server is 2012 and smo object version is from the latest sdk version 11.0 file .bak was created using sql management studio 2012, same local pc, on the same coding pc…
nam vo
  • 3,271
  • 12
  • 49
  • 76
13
votes
6 answers

SQL Server SMO complains of missing DLL

Ok, I've scoured the web, BOL, various forums and I'm no closer to an answer...hopefully you fine folks can lend a hand... We've got a dozen or so SQL Servers (some 2k, some 2005) on a network. I'm using SMO objects in a .NET application to get some…
Henry Lee
12
votes
4 answers

SQL Server: Why do use SMO?

I have been working with SQL Server for a couple of years. I have heard about SMO but I don't know anything about it. What are the benefits of using it? Should I learn and start using SMO in my SQL Server projects (mainly data warehouse…
juur
  • 5,633
  • 10
  • 32
  • 36
12
votes
4 answers

C# SMO backup of remote database to local machine

I have an application which performs backups and restores of SQL databases, this works fine on the local machine, however if I run this against a SQL server hosted on another machine I get the following…
Andy March
  • 586
  • 1
  • 5
  • 20
1
2 3
53 54