smo

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

不想你离开。 提交于 2019-12-20 04:28:15
问题 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

How to automate script generation using SMO in SQL Server?

丶灬走出姿态 提交于 2019-12-18 13:37:21
问题 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 SQL Server 2008. I don't have a clue about SMO and how to do this using SMO, so could you give me some advice (resources etc.) how to begin? 回答1: The key to SMO scripting is the Scripter class. All other tools (like SSMS) use this class to

SMO ConnectionContext.StatementTimeout setting is ignored

醉酒当歌 提交于 2019-12-18 07:05:21
问题 I am successfully using Powershell with SMO to backup most databases. However, I have several large databases in which I receive a "timeout" error "System.Data.SqlClient.SqlException: Timeout expired". The timout consistently occurs at 10 minutes. I have tried setting ConnectionContext.StatementTimeout to 0, 6000, and to [System.Int32]::MaxValue. The setting made no difference. I have found a number of Google references which indicate setting it to 0 makes it unlimited. No matter what I try,

Programmatically retrieve SQL Server stored procedure source that is identical to the source returned by the SQL Server Management Studio gui?

China☆狼群 提交于 2019-12-17 15:19:58
问题 Any pointers on how I can programmatically get exactly the identical stored procedure source from SQL Server 2005, as when I right-click on that stored procedure in SQL Server Management Studio and select modify? I'm trying using SMO, but there are some textual differences. The procedure always has CREATE, not ALTER, and there are some differences in the header, such as missing GOs in the version I'm getting programmatically. I can fix these up, but perhaps there is a better way? Again, I'm

How to restore a database from C#

孤人 提交于 2019-12-17 10:29:38
问题 I have a SQL 2008 DB. I am running a form that backs that DB up, then tries to update it. If the update fails the idea is to restore that backup. Here is the code I am using to restore the backup. public void RestoreDatabase(String databaseName, String backUpFile, String serverName, String userName, String password) { Restore sqlRestore = new Restore(); BackupDeviceItem deviceItem = new BackupDeviceItem(backUpFile, DeviceType.File); sqlRestore.Devices.Add(deviceItem); sqlRestore.Database =

Use different SMO version in the same VB.net application?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 07:39:08
问题 The SMO-libraries are for a specific version of SQL Server. So , is there any possibility to use different SMO libraries , in the same VB.net application in order that my application works regardless of SQL server version? Thank you ! 回答1: Yes! You can use older version of SMO-libraries for both servers. I used SMO-libraries from SQL Server 2008R2 in C# apllication and powershell script to migrate DB from 2008R2 to SQL Server 2005. Thus, there shan't be problems and when using VB.net. 来源:

SQL SMO DLL References v12 / v11 could not load

萝らか妹 提交于 2019-12-13 01:51:44
问题 I have created a C# application which referenced various v11 SQL Server SMO assemblies. I've done this by taking copies of these, referencing them with Copy Local=True in the properties of the Reference, and then including them with copies of the application. The application is deployed to 50 or so machines on our company network, some developer PCs, some servers. I started to receive the error Could not load file or assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version= 12 .0.0.0,

Get parent property in child select in Powershell?

有些话、适合烂在心里 提交于 2019-12-13 01:50:32
问题 I want to include a parent level property in a child result set in Powershell and I can't figure out how to do it. An example of what I want to do would be to include the ServerName as the first column of a pipe to get the DatabaseName and a list of Database properties of all the databases on the server similar to: [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null $s = New-Object ('Microsoft.SqlServer.Management.Smo.Server') "SQLSERVER" $s.Databases |

Is there a difference SMO ServerConnection transaction methods versus using the SqlConnectionObject property?

筅森魡賤 提交于 2019-12-12 13:04:04
问题 I am using SMO to create databases and tables on a SQL Server. I want to do so in a transaction. Are both of these methods of doing so valid and equivalent: First method: Server server; //... server.ConnectionContext.BeginTransaction(); //... server.ConnectionContext.CommitTransaction(); Second method: Server server; // ... SqlConnection conn = server.ConnectionContext.SqlConnectionObject; SqlTransaction trans = conn.BeginTransaction(); // ... trans.Commit(); 回答1: The two are equivalent.

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

心不动则不痛 提交于 2019-12-12 08:17:34
问题 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);