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

SqlServer.Management.SMO.Server error when beginning transaction

Having an error when using SMO. This code has been working in VB.Net 4 and was just moved to C# and is now not functioning. Microsoft.SqlServer.Management.Smo.Server server = new Microsoft.SqlServer.Management.Smo.Server( new…
Malcolm O'Hare
  • 4,879
  • 3
  • 33
  • 53
7
votes
2 answers

How To Backup And Restore DataBase With FILE STREAM Using SMO in C#

How can i backup and restore a database with file stream Using SMO in C#. i found some attributes in Server Class in SMO Like "FilestreamLevel" and "FilestreamShareName" but i do not know how to use them. please help and thanks for all
Muhammad Al-Own
  • 237
  • 3
  • 13
7
votes
5 answers

C# parse SQL statement to find all INSERT/UPDATE/DELETE tables used in stored procedures

As the title says my intention is to find all tables participating in either INSERT/UPDATE/DELETE statements and produce a structured format. So far this is what I've come up with - void Main() { string DBName = "Blah"; string ServerName =…
Soham Dasgupta
  • 5,061
  • 24
  • 79
  • 125
7
votes
3 answers

Retrieving database name from bak file

I have a bak file that has in it a back up of a database . I want to restore this database to a new location and I need to retrieve the database name from this file any idea how to do so ? I need it to override the data file location and the log…
Night Walker
  • 20,638
  • 52
  • 151
  • 228
7
votes
2 answers

Restart SQL Server instance using SMO

My C# application uses SMO to do various things with SQL Server instance chosen by a user. Particularly, it changes authentication mode: ServerConnection conn = new ServerConnection(connection); Server server = new…
Alex
  • 1,357
  • 3
  • 18
  • 41
7
votes
6 answers

How to drop and recreate and primary key index using SMO with SQL Server?

I am using SQL Server 2005 Express. I want to use SMO to loop through each table in a database and change each Char column to a Varchar column. If a column is a member of the primary key, I need to first drop the primary key before altering the…
YWE
  • 2,849
  • 28
  • 42
7
votes
1 answer

IsSystemObject attribute of smo

I am getting list of stored procedures from database by using SMO. I have foreach loop over stored procedures to make my intended operatioans on them. However I need to use only user created stored procedures. I use IsSystemObject attribute of…
osmanraifgunes
  • 1,438
  • 2
  • 17
  • 43
6
votes
1 answer

Using SMO to script out Object definitions from SQL server database in .net in Parallel loop

I am using SMO to script out my objects from Sql server database using .Net code. But as of now I am going through a sequential loop. foreach(var table in TableCollection) { var stringCollection=table.Script(); } It is working fine. But when I…
AjayK
  • 433
  • 5
  • 18
6
votes
4 answers

Checking for and dropping an existing table via C# and SMO

I am trying to look for a SQL table by name and if it exists drop it. This all needs to be done in C# using SMO. To complicate it a bit more the table also has a schema other then "dbo". Ultimatly the table will be recreated via SMO (I have this…
John S
  • 7,909
  • 21
  • 77
  • 145
6
votes
6 answers

SQL 2005 SMO - find referencing table

I need to change some primary keys from non-clustered to clustered but I can't drop the constraint because it is referenced from other foreign keys. How can I find the tables that reference a primary key in the parent table as part of a foreign…
Cosmin Onea
  • 2,698
  • 1
  • 24
  • 27
6
votes
2 answers

How to get the table a foreign key refers to

I have an small question I didn't found an answer yet: how do I get in c# and using Microsoft.SqlServer.Smo the table a foreign key column is referring to? foreach (Column column in currentTable.Columns) { if (column.IsForeignKey) { …
Ronnie
  • 4,959
  • 10
  • 51
  • 69
6
votes
9 answers

please explain the use of "default()" in this code

source http://technet.microsoft.com/en-us/library/ms162234%28SQL.100%29.aspx code //Connect to the local, default instance of SQL Server. { Server srv = default(Server); srv = new Server(); //Create a linked server. …
user287745
  • 3,071
  • 10
  • 56
  • 99
6
votes
5 answers

What's the fastest method to check SQL server availability?

What's the best method to check if SQL server exists or not? I'm trying Microsoft.SqlServer.Management.Smo.Server.PingSqlServerVersion() and it works fine if server exists and available. But it kinda pretty slow, if there is no such a server. Is…
iLemming
  • 34,477
  • 60
  • 195
  • 309
6
votes
5 answers

How to create ALTER scripts instead of CREATE scripts using SMO (Server Management Object)

I am using the Microsoft.SqlServer.Management.Smo classes to script out SQL scripts for stored procedures, tables, views etc. I am doing this for putting them in source control. Instead of the CREATE scripts for stored procedures, how can I get…
hIpPy
  • 4,649
  • 6
  • 51
  • 65
6
votes
2 answers

How to kill all connections to a SQL Server database using C# and SMO?

I'm trying to restore a database from a .BAK file using C# and SMO. This is my code. public static void RestoreDatabase() { string dbConnString = Configuration.DatabaseConnectionString; ServerConnection connection = new…
Rusty Wizard
  • 531
  • 6
  • 20
1 2
3
53 54