Click here to Skip to main content
15,885,990 members
Everything / SMO

SMO

SMO

Great Reads

by Fred Song (Melbourne)
Using replication, you can distribute data to different locations and to remote or mobile users over local and wide area networks, dial-up connections, wireless connections, and the Internet.
by bmckuhen
How to get a quick list of all DBs using SMO
by Morten Lossius
Copy tables between servers with smo - different collation
by Kanasz Robert
In this fourth part of the tutorial, I will show you how transfer objects and catch trace messages using SMO.

Latest Articles

by syed shanu
In this article, we will see how to create an easy SQL Server Tool.
by Fred Song (Melbourne)
Using replication, you can distribute data to different locations and to remote or mobile users over local and wide area networks, dial-up connections, wireless connections, and the Internet.
by qadirv
Quick C# console application to encrypt all your database stored procedures
by David_Wimbley
An alternate way of versioning your database using C# and SMO without buying expensive plugins.

All Articles

Sort by Score

SMO 

4 Nov 2015 by Fred Song (Melbourne)
Using replication, you can distribute data to different locations and to remote or mobile users over local and wide area networks, dial-up connections, wireless connections, and the Internet.
2 Dec 2013 by OriginalGriff
The first thing to do is put a breakpoint on the line: StringCollection strCol = table.Script();And look at the table variable - my guess it that it is null, which means that when you try to access any method or property you will get that error.So then, look at why.What is the...
17 Aug 2011 by bmckuhen
11 Jan 2012 by Wonde Tadesse
Have a look at this CodeProject article.Locate SQL Server instances on the local network[^].
2 Dec 2013 by Sergey Alexandrovich Kryukov
It cannot be as described. The line where the exception is thrown (if I can assume it is thrown actually in this line, which is not the 100% proven fact to me) clearly says that left reference-type value on left is assigned to the property value on right. Assigning null to null would not throw...
24 Apr 2011 by Kanasz Robert
Hello,Curren...
8 Sep 2011 by Kanasz Robert
Hi,I have written an article about scripting. more about that you can find here:SMO Tutorial 3 of n - Scripting[^]RegardsRobert
1 Nov 2011 by qadirv
Hi , You can check out the link below, it might help you make a refernce to the SMO object.Encrypting all the Stored Procedures of a Database[^]Regards
18 Jan 2012 by Morten Lossius
Copy tables between servers with smo - different collation
27 Apr 2020 by OriginalGriff
Have a look at this: Backing up an SQL Database in C#[^] - it's the code I use. It's in C#, but it's pretty obvious and it explains a number of the other pitfalls you need to be aware of when backing up SQL DBs.
15 Jun 2011 by Member 8009155
I am using a C# app via Visual studio 2010 that used SQLServer08. I am trying to come up with a simple way to manage DB schema changes. Manually changing everything is not an option as everything should be fully automated to compare and modify the databases. I was looking at the...
8 Sep 2011 by rayjohn1831
hi therecan anybody post me a little example, how to script db objects using SMO?
8 Sep 2011 by Mehdi Gholam
Follow this link to the Microsoft site which has all you need SQL Server Management Objects
11 Jan 2012 by koleraba
HiI am trying to get the names of all SQL server instances on the network. I am using the SMO (server management objects). The problem is that the call to SmoApplication.EnumAvailableSqlServers(false) returns a DataSet containing only the names of the servers not the installed instances....
12 Jan 2012 by koleraba
Hi It turn's out that the solution was simpler than I thought. The problem was that the SQL Server Browser service was stopped. When running the above smo command while the service is started you get all the running instances along with their properties(InstanceName, Version, IsClustered...
22 May 2012 by monoloox
I have written a windows form application with C#.Net using SMO for backup and restore the database. every now and then when I run the program I come across with this error message:See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog...
22 May 2012 by Wendelius
If you you get this occasionally, I take it that you have enabled the Named Pipes protocol.In either case, I'd suggest using purely TCP/IP. Named pipes have some (sometimes unresolved) problems and MS discourages their usage. For example active devices in your network may prevent the...
10 Jun 2012 by LTMKH
Dear All,I prepare Restore Application on C# to restore database from SQL server back up file ( *.BAK) using Microsoft.SqlServer.Management.Smo class as the following Code:private void RestoreDatabase(Restore res, TreeNode tn) { blRestoreCompleted = false; ...
13 Aug 2012 by rok_007
Hi,IS their any way to generate an alter script of a table, of two different versions.If we have a table T1 in Database Dv1, an extra column is added in T1 and the database is named as Dv2.Then i want to generate an alter script of that extra column.Using SMO,I could generate...
13 Aug 2012 by barneyman
There are 3 easy ways to do it, 2 are free, but require discipline 1. At every 'epoch', dump all the create files, run winmerge, or similar, over them and create the alters manually2. Mandate that all changes to DB structure are done with alter scripts, and simply collect and coalesce...
28 Aug 2012 by Hassan Boutougha
I find many workaround: After logging all script one by one for each SMO.Table, I discover that some script take less than 1 second, other take about 50 second!So a first workaround is to work with multithreading.Doing so, make my scripting that took 2 hours to take know only 20 minutes 600%...
11 Feb 2013 by Mashinchi
I developed a windows form application in visual stadio 2012 and I used SMO for backup and restoring database from SQL server 2008 R2.When I test the application in my system that SQL server 2008 R2 & VS2012 had been installed in it, I have not problem with SMO and it's work correctly....
18 Sep 2013 by Cenkay Vergili
My code lines(I am still a rookie. :)) ;I was trying to export the table on C# so after searching and trying hours I got this problem :|using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using...
18 Sep 2013 by Cenkay Vergili
Problem Solved! :P-Change your .NET Framework of your program to 4 .ThenYou gotta change your App.config like that ; ...
25 Nov 2013 by thatraja
Based on the error message & additional information, I got a thread, check it out.http://social.msdn.microsoft.com/Forums/sqlserver/en-US/479651b7-e838-4d4d-b298-02cf791ced57/the-integration-services?forum=sqlsmoanddmo[^]
2 Dec 2013 by Cenkay Vergili
An unhandled exception of type 'System.NullReferenceException' occurred in MyProject.exeAdditional information: Object reference not set to an instance of an object.It says , StringCollection strCol is null, but table.Script() is not null(it includes the record.)Here my codelines ...
18 Jan 2014 by Member 10533328
I want to create a C# web application which get Server Name , Instance , User , Password of Remote Sql Servers from user and run a query on their databases. I also want to save Remote Sql Servers info in order to reuse them . Please Help me how to start . Is it essential to use SMO ?
18 Jan 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Basically, you will form the ConnectionString from the User Inputs and connect to the Database.Without using SMO, you can achieve the task by ADO.NET Objects.You need to form that ConnectionString, then Connect to that Server using SqlConnection Class.Initialize SqlCommand Class and do...
25 Mar 2014 by Member 10448584
how to copy .mdf and .ldf files from sql server folders to any other location using c#
25 Mar 2014 by ZurdoDev
You can use the File.Copy method in System.IOhttp://msdn.microsoft.com/en-us/library/system.io.file.copy(v=vs.110).aspx[^]
23 Aug 2014 by MSDesigner
Hi guys;I would like to Backup and Restore my application's dataBase, using SMO commands.Problem is : When I restore my file called " tpMedia_Database.bak " , It creates a file named " tpMedia_Database_new.mdf" based on my codes , but if I restore it again, it does not work.I mean , to...
4 Feb 2015 by Member 11414041
I am stuck at a point where I have to create a table in SQL and apply foreign key constraint. The problem is I need to do that from C# code.
4 Feb 2015 by Peter Leow
Ask MSDN - Creating, Altering, and Removing Foreign Keys[^]
6 Feb 2015 by Member 11414041
How can we create a composite key for SQL tables while creating new table. The code needs to be implemented in c#.net
6 Feb 2015 by Member 11414041
I have created primary and foreign key using SMO, but now I need to convert the primary key into composite key. There is no solution I am getting to. I can recreate the table, but it would be great if I don't need to recreate tables, and create the primary key into composite key.
3 Mar 2015 by Member 11494479
Alert me | Edit | Change typeQuestionYou cannot vote on your own post0I have different versions of SMO installed on my machine. Is there any method to know the latest version of SMO installed through program?I mean is there any API or something like that for the purpose?For example,...
5 Mar 2015 by Member 11502168
I am trying to create a database using SMO. I get this exception on the Create():Create failed for database.An exception occurred while executing a Transact-SQL statement or batch.I tried may solutions and nothing worked. I ran the VS as administrator, the MSSMS too, I set the...
12 Sep 2016 by Arvind61
I' ve been writing a setup with the following code to attach a database to sql server 2008 using SMO in VB.Net 2010: Dim srv As New Smo.Server()Dim strDataFile As String = "Application.StartupPath + \dbPatientLabWork.mdf"Dim logDataFile As String = "Application.StartupPath +...
12 Sep 2016 by RossMW
Just to close the question off..Set the strColl.Add values with the files full directory path.
22 Dec 2017 by RickZeeland
Here is an SMO application that might get you started: SMO Tutorial 3 of n - Scripting[^]
21 Aug 2018 by Member 13955949
hi i have database that have 250 tables and i want to do specific change design in some of tables like renaming column ,changing datatype ,add identity ,changing primary key and add unique key . I don't want to do in manually in SSMS and run change script i want to do it with program in C# that...
27 Apr 2020 by Mohamed Aboelkheer
Wellcome I Want To Do Backup and Restore SQL Database Using SMO Library in vb.net I used Certain codes But failed attempts Please advise a specific code Greetings What I have tried: Imports Microsoft.SqlServer.Management.Smo Imports...
22 Jan 2012 by Kanasz Robert
In this fourth part of the tutorial, I will show you how transfer objects and catch trace messages using SMO.
18 Nov 2014 by qadirv
Quick C# console application to encrypt all your database stored procedures
19 Aug 2013 by David_Wimbley
An alternate way of versioning your database using C# and SMO without buying expensive plugins.
2 Feb 2016 by syed shanu
In this article, we will see how to create an easy SQL Server Tool.
27 Apr 2011 by Kanasz Robert
OK. I found a solution: Server srv = new Server(new ServerConnection("SERVER", "USERID", "PASSWORD")); srv.SetDefaultInitFields(typeof(Table), true); Database db = srv.Databases[database]; ScriptingOptions so = new ScriptingOptions(); so.AllowSystemObjects = false; var...
11 Apr 2012 by jroughgarden
This is an alternative for "Encrypting all Stored Procedures of a Database".
27 Apr 2020 by RickZeeland
Although most examples use SMO to backup and restore, this is not needed at all and can lead to problems when using a different SQL Server version as Microsoft sometimes changes the SMO dll's and functionality. Here are some examples that do not...
25 Nov 2013 by Cenkay Vergili
SmoException was unhandled,An unhandled exception of type 'Microsoft.SqlServer.Management.Smo.SmoException' occurred in Microsoft.SqlServer.SmoExtended.dllAdditional information: The Integration Services component is not installed or you do not have permission to use it. Server...
23 Apr 2014 by bunzitop
I've script generated of database(sql 2005). I am trying to create database using that script during deployment of application.It throws error message The size associated with an extended property cannot be more than 7,500 bytes. How can i get rid of this problem?
17 Jun 2011 by AlexCode
I use the Visual Studio 2010 DataBase project.This is actually very easy to use and lets you schema compare the database with the project and the other way around.It also delivers a Data Comparison tool that lets also sync the data on the database.I tried to find a very simple tutorial...
10 Jun 2012 by arindamrudra
This [Link] contains the SQL script to restore multiple database from one .bak file. You can use this query to execute from your application.
22 Dec 2017 by Member 13548480
I have two table having same schema and i want to compare both table to get different record in separate table. What I have tried: I am using smo approach to solve this problem.