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
0
votes
2 answers

C# SMO Select from Database

I have been racking my brain trying to figure out how to execute a SELECT from Table using SMO in C# and returning that value to a string item. I have seen multiple posts of how I can run a SQL script from within C# which is not what I want to do. …
ondrovic
  • 1,105
  • 2
  • 23
  • 40
0
votes
1 answer

SMO SQL job creation and clustered servers - as simple as I think it is?

As part of our deployment process, we use SMO to create SQL jobs programmatically on the server as part of the configuration needs to be dynamic, and it also makes the entire process automatic for us. This has been working well for the past few…
stevehayter
  • 796
  • 1
  • 7
  • 23
0
votes
0 answers

PowerShell MSSQL SMO Scripter - Script inserts on filtered data

I am trying to generate data inserts that are filtered based on column data. We have no problems scripting out all of the data using the scripter.Options.ScriptData and using the EnumScript method. Our goal is to script out inserts for a result…
0
votes
2 answers

Why isn't my method returning any valid SQL Server instances?

I have a piece of code that is supposed to return all instances of SQL Server installed on my machine. It looks like this: DataTable dtLocalServers = SmoApplication.EnumAvailableSqlServers(true); foreach (DataRow dServer in…
ijb109
  • 942
  • 1
  • 19
  • 30
0
votes
2 answers

asp .net page to backup sql db

I'm trying to create an asp .net page to backup and download an mssql db from my remote host on a shared server. I tried using SMO to create a backup and save it the same folder as the .aspx page but it throws an access denied exception, I later…
user179200
0
votes
1 answer

Single User after renaming an MS-SQL database

I am using help of SqlServer.Management.Smo to rename an attached MS-SQL database. Dim db As New Database = ActiveSQLServer.Databases(OLD_NAME) db.ExecuteNonQuery("ALTER DATABASE " & OLD_NAME & " SET SINGLE_USER WITH ROLLBACK…
OrElse
  • 9,709
  • 39
  • 140
  • 253
0
votes
2 answers

Where can I download the SQL Server 2008 SMO dlls

I had the SQL Server 2008 dlls, and I installed SQL Server 2008R2 Feature Pack. Rather than putting them in Program Files/105/SDK, it put them in Program Files/100/SDK and overwrote my 2008 SMO dlls. There are some slight differences, and I need to…
Paul Draper
  • 78,542
  • 46
  • 206
  • 285
0
votes
1 answer

Why does defining a variable of type of Smo.Server cause a 10 second delay

Bear with me here, ok!! We use SMO a lot to do all kinds of things, including to check for the presence of particular stored procedures in the database. So we have a method in our data access class called HasProc, which returns a boolean. It's in…
ChrisA
  • 4,163
  • 5
  • 28
  • 44
0
votes
1 answer

SQL SMO to script INSERT with row constructors

I have written the following PowerShell code to export data from a table as INSERT statements: [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null $srv = new-object Microsoft.SqlServer.Management.SMO.Server $db =…
Allanrbo
  • 2,278
  • 1
  • 23
  • 27
0
votes
0 answers

Using Microsoft.SqlServer.Management.Smo to get performance metrics

Was wondering how I can programmatically get performance metrics for a given sql server instance or database by using SMO (sql management objects). Basically similar to what the Activity Monitor in Sql Management Studio displays. So for example if I…
0
votes
2 answers

SMO Stored Procedure Alter fail

I am trying to alter the parameters in a stored procedure programatically in c#. I came across SMO and have been trying to use it but the alter keeps failing. Here is my code: //alter parameter data type in stored procedure if parameter is not …
coffeeak
  • 2,980
  • 7
  • 44
  • 87
0
votes
1 answer

How to display ndf files using SMO?

I am using SMO to populate the list of database files log files. i am using filegroups but it displays only mdf and ldf files. I have ndf files also it is not dispalying ndf files?? what i have to do any suggestions plz??? string dbname =…
Cute
  • 13,643
  • 36
  • 96
  • 112
0
votes
1 answer

SQL Server SMO: drop multiple objects with dependencies

Given a set of objects (tables, views, procs, ...) I want to drop all of them and all objects that depend on them. This requires executing the drop operations in dependency order for both the objects that I want to drop as well as all dependent…
usr
  • 168,620
  • 35
  • 240
  • 369
0
votes
1 answer

Generating foreign key drop powershell script with SMO

I have the following powershell script to generate a script to drop foreign keys, using SMO ($scripter is a Scripter object, and $db is a Database object): $scripter.Options.ScriptDrops = $true; $scripter.Options.DriForeignKeys =…
Tola Odejayi
  • 3,019
  • 9
  • 31
  • 46
0
votes
1 answer

How to alter a table using SMO

I'm using SMO to create table dynamically in Sqlserver 2008.now I would like to add new columns for existing table using SMO, but I'm trying to execute the code the finally getting run time exception as "alter fail to table".My code snippet as …
Srinivas Adari
  • 105
  • 1
  • 2
  • 13