smo

Can't find Microsoft.SqlServer.ConnectionInfo.dll assembly file?

我们两清 提交于 2019-12-03 22:51:33
I'm trying to dynamically get a databases Table structure using only C# code as follows: using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo; public class LoadStuff { ... public void LoadDatabase(string vDatabaseName) { using (var vSqlConnection = new SqlConnection(DatabaseConnectionString)) { var vConnection = new ServerConnection(vSqlConnection); var vServer = new Server(vConnection); var vDatabase = vServer.Databases[vDatabaseName]; var vTables = vDatabase.Tables; } } } However, I cannot find the .dll file to add a reference too. I'm using Visual Studio

Need help connection with Microsoft.SqlServer.Management.Smo Transfer class

空扰寡人 提交于 2019-12-03 20:39:12
I am trying to copy everything (data, indexes, triggers, stored procedure). From one database to another in C#. Here is my code: SqlConnection connection = new SqlConnection(ConnectionString); Server myServer = new Server(new ServerConnection(connection)); Database db = myServer.Databases[this._myDB]; if (myServer.Databases[this._newDB] != null) myServer.Databases[this._newDB].Drop(); Database newdb = new Database(myServer, this._newDB); newdb.Create(); Transfer transfer = new Transfer(db); transfer.CopyAllSchemas = false; transfer.CopyAllStoredProcedures = true; transfer.CopyAllTables = true;

Use smo to rename datafiles

谁说胖子不能爱 提交于 2019-12-03 20:31:28
How can I use SMO to rename the physical .mdf .ndf .ldf files. This article was helpful but I need to use C# SMO Objects. Using the SMO Server Object I can retrieve the database, then Get Access to the DataFile objects. Per this link . These have a Rename, however after rename, nothing changes. Well, I haven't tried this, but as per your first link, you can detach the database, rename the file on disk and then re-attach the database. So, give that a shot. The Server object in SMO has a Detach(..) and Attach(..) methods that you can use. Then, just use File.Move(..) to rename the file. 来源:

SQL SMO To Execute Batch TSQL Script

♀尐吖头ヾ 提交于 2019-12-03 15:43:38
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 connection string no longer exists // because we dropped it already var builder = new SqlConnectionStringBuilder(connectionString) { InitialCatalog = "master" }; using (var sqlConnection = new SqlConnection(builder.ToString())) { var serverConnection = new ServerConnection(sqlConnection); var server = new Server(serverConnection); // hangs here for

SMO and Sql Server 7.0

拜拜、爱过 提交于 2019-12-02 09:16:24
Does anyone have a definitive answer to whether Sql Server Management Objects is compatible with Sql Server 7.0? The docs state: Because SMO is compatible with SQL Server version 7.0, SQL Server 2000, SQL Server 2005, and SQL Server 2008, you easily manage a multi-version environment. But trying to connect to a Sql 7 instance gets me: "This SQL Server version (7.0) is not supported." Has anyone been successful in getting these 2 to play nice? you can use SMO to connect to SQL Server versions 7, 2000, and 2005, but SMO does not support databases set to compatibility levels 60, 65, and 70. for

SQL Azure: SMO Exception when scripting objects in SSMS 2008 R2

冷暖自知 提交于 2019-12-02 08:33:35
问题 I am using SQL Server Management Studio 2008 R2 to manage a SQL Azure database. When I try to right-click on any of the objects in the database, and do Script Table As -> CREATE -> New Query Editor Window, I get the following exception screen every time: Scripting for SELECT -> New Query Editor Window is the only option that seems to work without generating an Exception like above. Any ideas?? 回答1: Here are additional details about this issue. Latest service update for SSMS: http://support

How to Connect to Sqlserver2008 using SMO any workaround has to be done?

旧巷老猫 提交于 2019-12-02 06:52:34
I wrote this for finding the sql server instances on the local machine: using System; using System.Data; using Microsoft.SqlServer.Management.Smo; namespace Application3 { class Program { static void Main(string[] args) { string srvname = string.Empty; string srvnames = null; DataTable dt = SmoApplication.EnumAvailableSqlServers(true); Console.WriteLine("------------->" + dt.Rows.Count); foreach (DataRow dr in dt.Rows) { try{ Console.WriteLine("-->Instance " + dr["name"]); Server srv = new Server((string)dr["name"]); foreach (Database db in srv.Databases) Console.WriteLine(db.Name); }catch

Scripting out individual objects from SQL using SMO

▼魔方 西西 提交于 2019-12-02 06:29:10
For my job I often have to script out a table with all its keys, constraints and Triggers (basically a full script to recreate the table) from a Microsoft SQL 2008 server.I also have to do this for procedures and triggers. What I do now is open SSMS right click the object and select script to and select to script it to a file. So if I have 3 procedures to do and 10 tables and 1 trigger I end up doing this 14 times . What I would like is a powershell script that I could feed a list of objects to and then it would go and use SMO to script each on out to an individual file. Thanks for the help

EnumAvailableSqlServers returns empty list

吃可爱长大的小学妹 提交于 2019-12-02 05:34:34
问题 I have a strange situation where i have added a reference to Microsoft.SqlServer.Smo Microsoft.SqlServer.ConnectionInfo Microsoft.SqlServer.Management.Sdk.Sfc and a call to SmoApplication.EnumAvailableSqlServers returns a DataTable of available servers, when it is run on my development machine. When I deploy to my colleague's machine, the DataTable is returned empty. Strangely, the following Dim server As New Microsoft.SqlServer.Management.Smo.Server("localhost\sqlexpress") For Each db In

SQL Azure: SMO Exception when scripting objects in SSMS 2008 R2

a 夏天 提交于 2019-12-02 03:53:22
I am using SQL Server Management Studio 2008 R2 to manage a SQL Azure database. When I try to right-click on any of the objects in the database, and do Script Table As -> CREATE -> New Query Editor Window, I get the following exception screen every time: Scripting for SELECT -> New Query Editor Window is the only option that seems to work without generating an Exception like above. Any ideas?? Here are additional details about this issue. Latest service update for SSMS: http://support.microsoft.com/kb/2507770 Blog discussing the necessary upgrade: http://social.msdn.microsoft.com/Forums/en-AU