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
1 answer

Microsoft.SqlServer.Management.Smo.Server.Jobs.Job.EnumHistory() is limited to 100 rows

I am trying to write a script to scan for Sql Maintenance Task failures - see script below. I appear to be unable to process more than 100 entries using EnumHistory(). Does anyone have a way around this? Param( [int]$days="30" # this hardly…
David Rogers
  • 4,010
  • 3
  • 29
  • 28
0
votes
1 answer

How can I optimize my PowerShell SMO Query (where-object is too slow)?

A. Is there the possibility to get the result of ps-script: $ss=New-Object Microsoft.SqlServer.Management.Smo.Server 'MyServer'; $ss.Databases[$db].Tables | Where-Object {$_.IsIndexable -eq $true} with the comparable performance to the…
Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142
0
votes
2 answers

Restore database using c# and smo

I am trying to restore a sql server .bak into an empty database using the following c# code: string dbBakFile = GetBackFileFromZip(restoreConfig.TmpUnZipFolder,restoreConfig.DatabaseFileToRestore); if…
Ismail
  • 923
  • 2
  • 12
  • 29
0
votes
1 answer

PowerShell SMO Error Handling Empty or Null

I have a script that gets SQL Server properties using SMO. I have the script display the properties out in html but I am having trouble setting it up so that the script still enters a datarow even when the SMO object returns empty because of a…
Skunny11
  • 39
  • 1
  • 3
  • 13
0
votes
1 answer

SMO and Sproc Class Generation

I am attempting to build a DAL generator for myself. While most of it has gone perfectly, I am a bit stuck when it comes to my sprocs. In my database, I have a set # of sprocs that are simple select statements, such as: ALTER PROCEDURE…
Kevin
  • 2,684
  • 6
  • 35
  • 64
0
votes
2 answers

Smo user created stored procedure

When I try to get the list of stored procedures from db by using smo, it lists a lot of stored procedures even if the database is empty. I want to be able to get a list of stored procedures that are not system procedures. IsSystemObject is not…
osmanraifgunes
  • 1,438
  • 2
  • 17
  • 43
0
votes
1 answer

Backup from database with SMO failed

Backup from SQL Server 2008 R2 databese using SMO is not working : BACKUP DATABASE is terminating abnormally. Source=.Net SqlClient Data Provider ErrorCode=-2146232060 Class=16 LineNumber=1 Number=3201 Procedure="" Server=(local) …
Mostafa
  • 91
  • 2
  • 12
0
votes
1 answer

set sql agent job schedule time in C#

I want to schedule a group of queries run weekly/configurable.I found below code by googling but am trying to set sheduler timings for weekly execution now.Also i want it to be configurable. Am pretty new to this so somw help would be appreciated! …
Murali Uppangala
  • 884
  • 6
  • 22
  • 49
0
votes
1 answer

NullReference Exception was unhandled in foreach

An unhandled exception of type 'System.NullReferenceException' occurred in MyProject.exe Additional information: Object reference not set to an instance of an object. It says , StringCollection strCol is null, but table.Script() is not null (it…
0
votes
2 answers

SMO.Transfer: cannot convert type "database" to type "database"

Here is a powershell script: [string] $server = "devserver\mssql"; # SQL Server Instance [string] $database = "ftg"; # Database with the tables to script out. [string] $folder = "d:\FT\FTProject\"; # Path to export…
host.13
  • 108
  • 1
  • 1
  • 11
0
votes
2 answers

Is it possible to get hostnames of computers connected to MS SQL database?

with following code you list all users that are connected to certain DB [System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.SMO’) | out-null $Sql = New-Object (‘Microsoft.SqlServer.Management.Smo.Server’) “DEVSQL” $DB =…
Primoz
  • 4,079
  • 17
  • 56
  • 67
0
votes
1 answer

Microsoft.SqlServer.SMO included in app

I am currently writing a backup application in c# using the Microsoft.SqlServer.SMO components and running into some issue getting the application to launch / run on anything other than my dev machine. I am using the ones included with SQL Server…
ondrovic
  • 1,105
  • 2
  • 23
  • 40
0
votes
2 answers

create entities for a dynamically created database in SQL Server

I have an application where I create database's dynamically in a SQL Server using Server Management Objects through my application. I want to use the Entity Framework to access this database when it has been created, is this possible? As I can…
Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
0
votes
2 answers

SMO fails to execute script with user-defined table type

I am trying to execute a sql script read from a file; however, when I go to execute the script I am met with the exception: Column, parameter, or variable #1: Cannot find data type dbo.ExistingTableType. Must declare the table variable…
BenM
  • 553
  • 1
  • 6
  • 23
0
votes
1 answer

Create a Sqlserver.Management.Smo column that is autoincremented

I am currently creating a database like this : var database = new server(serverconnection blah blah); var table = new Table(database, "tablename"); var name = new Column(tab, "Name", DataType.NVarChar(255)); tab.Columns.Add(name); var something =…
SmashCode
  • 4,227
  • 8
  • 38
  • 56