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

Using SMO Restore Class when there are multiple backup points in .bak file

I am attempting to use SMO to write a simple utility to backup/restore databases. This works very well when there is only one point in time in the backup file. However when there is a backup file that has multiple backup points defined (not backup…
Chuck Russell
  • 155
  • 1
  • 1
  • 9
6
votes
1 answer

Using SMO.Agent to retrieve SQL job execution status - security issue

I've got a C# program that fires off SQL Server Agent jobs using the SQL Server Management Objects (SMO) interfaces. It looks something like: Server ssis_server = new Server( new ServerConnection(SERVER_NAME, SERVER_USERNAME,…
dalyons
  • 1,304
  • 3
  • 15
  • 23
6
votes
1 answer

Timeout issue in Backup-SQLDatabase cmdlet

I’m trying to take back-up of a large database using “Backup-SQLDatabase” cmdlet using following statement, but I’m getting time-out error after 10 minutes. {Backup-SqlDatabase -ServerInstance $Server -Database $DatabaseName -BackupFile $BackUpFile…
zerocool18
  • 523
  • 1
  • 4
  • 11
6
votes
2 answers

How can I get the return value from Sql Server system message?

I am trying to verify the backup I have just done in c# using command against sql server Express string _commandText = string.Format("RESTORE VERIFYONLY FROM DISK = '{0}'", backupLocation); SqlDataReader _sqlDataReader =…
kurasa
  • 5,205
  • 9
  • 38
  • 53
5
votes
2 answers

SMO.Restore.SqlRestore sometimes throws a timeout exception on deployed computers

I have a app used for managing databases for demos of our software, one of the things that it does is get a copy of a database from a central server and restore it to a local SQL instance. Everything works correctly on the backup portion but on the…
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
5
votes
2 answers

Restore database from .bak file with new name

I am sing C#, .NET 3.5, and SMO to create a copy of a database (our production database) to some other databases (our DEV and Test-database) in SQL Server 2005. I have managed to create a backup from a database, an to restore it. this of course…
Martin
  • 195
  • 1
  • 12
5
votes
2 answers

Backup fails using smo on big databases

I use vb.net to backup sql '05 - '08 databases. It works great on smaller databases. but when it comes to large databases it fails at 30 or 40 percent with the error: The backup or restore was aborted. Dim objBackup1 As Backup = New Backup()…
Ezi
  • 2,212
  • 8
  • 33
  • 60
5
votes
3 answers

C# SMO - Scripting Table Data to File. Throwing Error

I'm trying to create a backup of the data contained within my database before I re-create the tables. I've got so far as to connect to the server and create the file to store the SQL. The problem is its throwing an error on the last line. "Object…
Mark OB
  • 492
  • 1
  • 7
  • 15
5
votes
5 answers

Sql SMO: How to get path of database physical file name?

I am trying to return the physical file path of a database's mdf/ldf files. I have tried using the following code: Server srv = new Server(connection); Database database = new Database(srv, dbName); string filePath =…
bv8z
  • 965
  • 2
  • 9
  • 19
5
votes
5 answers

What's the best way to detect the presence of SMO?

I have some code that uses SMO to populate a list of available SQL Servers and databases. While we no longer support SQL Server 2000, it's possible that the code could get run on a machine that SQL Server 2000 and not have the SMO library…
Chris Miller
  • 4,809
  • 4
  • 33
  • 50
5
votes
2 answers

SQL SMO To Execute Batch TSQL Script

I'm using SMO to execute a batch SQL script. In Management Studio, the script executes in about 2 seconds. With the following code, it takes about 15 seconds. var connectionString = GetConnectionString(); // need to use master because the DB in the…
Jeff
  • 35,755
  • 15
  • 108
  • 220
5
votes
2 answers

SMO not available in .NET 4.0? Or is there an easier way to backup a database from code

We upgraded our application to .NET 4.0 a while ago, and now need to add the ability to backup SQL Server 2008 databases from the app. However, it doesn't seem that SMO is available for .NET 4. Is there a workaround or better way to perform a…
Beep beep
  • 18,873
  • 12
  • 63
  • 78
5
votes
2 answers

Cleaning up after calls to SMO Server and Database

How do you make SMO release it's connections? I have this code: public static class SqlServerConnectionFactory { public static Server GetSmoServer() { using (var c = new…
Kjensen
  • 12,447
  • 36
  • 109
  • 171
5
votes
3 answers

How to automate script generation using SMO in SQL Server?

I would like to automate script generation (in SSMS --> Tasks --> Generate Scripts) in SSMS 2008. I have read that SQL Server 2008 does not support Database Publishing Wizard (including SQLPUBWIZ SCRIPT) but this automation can be done using SMO in…
juur
  • 5,633
  • 10
  • 32
  • 36
5
votes
2 answers

SQL Server SMO take back up locally from remote server

My question is straight forward, how can I program SQL SMO to take local backup, by connecting to a remote server. I want to save the bak file to a local machine which is connecting to the remote server. Also I want users with only certain…
Soham Dasgupta
  • 5,061
  • 24
  • 79
  • 125