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

How to copy tables base on schema name in Microsoft.SqlServer.Management.Smo.Transfer

I am copying tables from Source_Test database Destination_Test database. Using Microsoft.SqlServer.Management.Smo.Transfer. It's copies all the tables from Source_Test to Destination_Test But i want tables having schema 'TestSchema'. Main problem…
Hemant Malpote
  • 891
  • 13
  • 28
5
votes
1 answer

Using C# & SMO, how do I add a backup device to a SQL Server?

I know how to use C# and SMO to create a file backup on a SQL Server: public void BackupDatabase(Microsoft.SqlServer.Management.Smo.Server server, string databaseName, string backupFilename, …
C-Pound Guru
  • 15,967
  • 6
  • 46
  • 67
5
votes
3 answers

Get length of Columns using SQL Server Management Objects (SMO)

I'm writing T4 templates to generate CRUD stored procs etc I am looping through the columns of a table using SMO: For Each column As Column In table.Columns WriteLine("@" & column.Name & " " & column.DataType.Name & ", ") Next My question is…
DannykPowell
  • 1,227
  • 5
  • 18
  • 30
5
votes
1 answer

SMO code support to both sql 2005 and sql 2008

Prepared a manged c# DLL using assemblies of SMO of version:10.0.0.0 of SQL 2008 and I called the functions in this DLL from an unmanged c++ code. This application is running successfully for SQL Server 2008 but this application is throwing…
user186246
  • 1,857
  • 9
  • 29
  • 45
5
votes
2 answers

using SMO .net to backup and restore through DeviceType.Pipe

I wrote a Program that backup SQL Databases using SMO Library on .net , and everything is just going smoothly, I just have one last point, I'm changing my way to save the .bak file on the hard disk, from DeviceType.File to DeviceType.Pipe, I have…
Arrabi
  • 3,718
  • 4
  • 26
  • 38
5
votes
1 answer

Including DLL in dacpac file

I am hoping to use SMO to deploy a dacpac onto a remote SQL environment, away from my own development machine. In my project I reference a .dll file that is outputted into my build directory when I press "Build Solution". Is it possible to bundle…
5
votes
4 answers

Script Table With Data from code

In SQL Server 2008 R2, a user can script out a table with the data by right clicking on the database, selecting Tasks and Generate Scripts. A wizard will pop up, asking users what they want (multiple tables, one table, etc) along with some advanced…
Question3CPO
  • 1,202
  • 4
  • 15
  • 29
5
votes
4 answers

Execute SQL script from C# and logging errors

I am trying to execute a script (.sql file) on a database from a C# Windows application. The SQL file contains 'GO' statements; this means I am using the object SMO. I am trying to continue on error and also log any error which might occur during…
naregkar
  • 363
  • 6
  • 16
5
votes
4 answers

How to list available instances of SQL Servers using SMO in C#?

Can anybody explain me what I wrong I am doing in the following piece of code: DataTable dt=SmoApplication.EnumAvailableSqlServer(true); Server sr = new Server("Test"); foreach(DataBase db in sr.DataBases) { Console.WriteLine(db["name"]); } It…
Cute
5
votes
1 answer

Run .sql file from Application in C# using SMO library

I am building an application in C# visual studio 2012 RC. I have to run the scripts within the application. for this i am using. These two libraries. My application's target .net framework is 4.5. using Microsoft.SqlServer.Management.Smo; using…
Khizar Ali
  • 486
  • 2
  • 12
  • 26
4
votes
2 answers

SQL Server SMO - Backuping - How to determine failure / success?

If you execute backup using SMO, after successful completion, I test the SqlError for null, considering that the backup completed without errors: But, as you can see, it actually return an error of class 0 number 3014 meaning success. So the…
Denis Biondic
  • 7,943
  • 5
  • 48
  • 79
4
votes
2 answers

Disconnect active SQL connections from SMO

Is there a way to use SMO to disconnect all active users from a SQL database, so I can perform a database restore? The question linked to below is similar, but does not discuss the use of SMO. When restoring a backup, how do I disconnect all active…
user189198
4
votes
1 answer

Can I distribute and install SQL Server Server Management Objects with my application?

For an application, I am building, I want to use SQL Server Managentment Objects. Am I allowed to distribute and install SMO DLL's with my application? The application requires a SQL Server installation (and therefore license), but not necessarily…
Kjensen
  • 12,447
  • 36
  • 109
  • 171
4
votes
2 answers

How can I retrieve SQL Stored Procedure Parameter's with SMO more efficently?

I'm attempting to retrieve the DefaultValue of all the parameters in a StoredProcedure. My application is build in C# .NET accessing a Microsoft SQL 2008 Database. I use the SqlCommandBuilder.DeriveParameters to get most of the parameter…
Justin
  • 10,667
  • 15
  • 58
  • 79
4
votes
3 answers

Using cursors to read time series data from SQL Server using C#?

I have a large database (50 million rows) containing time series data. There is a clustered index on the [datetime] column which ensures that that the table is always sorted in chronological order. What is the most performant way to read the rows of…
Contango
  • 76,540
  • 58
  • 260
  • 305