smo

How to set CommandTimeout

你。 提交于 2020-01-13 08:29:07
问题 I am using Microsoft.SqlServer.Management.Smo . My Code: Server server = new Server(new ServerConnection( new SqlConnection(ConnectionString)); server.ConnectionContext.ExecuteNonQuery(script); I want to set CommandTimeout for it like we do with normal SQLCommand Please tell me how to set CommandTimeout for queries running through Microsoft.SqlServer.Management.Smo.Server 回答1: Try server.ConnectionContext.StatementTimeout 回答2: You can set command timeout using the SMO object as shown below:

How to use transactions in SMO.Server ConnectionContext

心不动则不痛 提交于 2020-01-11 10:30:51
问题 Following examples 1, 2 I wrote the following: using System; using System.Data.SqlClient; using System.IO; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common; namespace ScriptRunner { class Program { static void Main(string[] args) { var script = File.ReadAllText("Test.sql"); const string sqlConnectionString = @"Data Source=my\ds; Initial Catalog=myic; Connection Timeout=0; Integrated Security=true"; SqlConnection connection = null; Server server = null; try

Achieving consistent sorting between c# and SQL using CollationInfo.Comparer

耗尽温柔 提交于 2020-01-11 10:03:07
问题 I am attempting to use CollationInfo.Comparer from SMO to get my c# code to sort like SQL Server. I have gotten the correct collation, but my items still do not sort correctly. var collationInfo = CollationInfo.Collations.Single(x => x.Name == "SQL_Latin1_General_CP1_CS_AS") as CollationInfo; var comparer = collationInfo.Comparer; int c = comparer.Compare("Tri-Valley L", "Trimble L"); In this case c returns '1' indicating that Tri-Valley L will come after Trimble. However this code in SQL

How to get the table a foreign key refers to

天大地大妈咪最大 提交于 2020-01-11 05:23:09
问题 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) { //GET TABLE FOREIGN KEY REFERS TO } } 回答1: You should start from the table itself, and enumerate all of it's foreign keys. Sample code: foreach (ForeignKey key in currentTable.ForeignKeys) { foreach (ForeignKeyColumn column in key.Columns) { Console.WriteLine(

Can't enumerate SQL Server 2008 Registered Servers with SMO

痞子三分冷 提交于 2020-01-05 06:49:06
问题 I had SQL Server 2005 Management Studio installed on my workstation. I have since installed SQL Server 2008 workstation tools and removed the SQL Server 2005 tools. I am now writing a c# program which iterates my registered servers in management studio. Problem is, it is iterating through my old list in the 2005 tools (which have now been uninstalled) and not my 2008 registered servers list. I thought it might be an assembly references issue, so I check that my SMO assembly references are

Backup and restore Azure database programmatically with smo

让人想犯罪 __ 提交于 2020-01-04 06:28:09
问题 We have a running web application. Everything is hosted on azure. We have one sql server and two databases: production and test. Client requested functionality to backup production db and restore it in place of test db. I am using following code: public static void BackupDatabase(string databaseName, string userName, string password, string serverName, string destinationPath) { try { Backup sqlBackup = new Backup(); sqlBackup.Action = BackupActionType.Database; sqlBackup.BackupSetDescription

Backup and restore Azure database programmatically with smo

て烟熏妆下的殇ゞ 提交于 2020-01-04 06:28:07
问题 We have a running web application. Everything is hosted on azure. We have one sql server and two databases: production and test. Client requested functionality to backup production db and restore it in place of test db. I am using following code: public static void BackupDatabase(string databaseName, string userName, string password, string serverName, string destinationPath) { try { Backup sqlBackup = new Backup(); sqlBackup.Action = BackupActionType.Database; sqlBackup.BackupSetDescription

How to find if SQL Server 2008 Management Objects installed?

懵懂的女人 提交于 2020-01-04 05:55:36
问题 My application needs SMO libraries to be installed. I want my installer to verify if SQL Server 2008 Management Objects already installed and if not install the SMO feature pack bundled with my installer. How do I find out if it is already installed? Is there any registry key to verify? Thanks, Hem 回答1: Solution for SQL Server 2012: HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\SharedManagementObjects\CurrentVersion\Version You can check if this key exists (and check if the value is greater

Backing up database with SMO

爱⌒轻易说出口 提交于 2020-01-04 05:40:30
问题 I have created a class to backup a database, the code is: public bool BackupDatabase(string databasename) { bool success = false; try { Backup dbBackup = new Backup(); string SqlInstance = @"SERVER\INSTANCE"; string User = ExtractPureUsername(System.Security.Principal.WindowsIdentity.GetCurrent().Name); string BackupLocation = @"\\SERVER\FOLDER\BACKUPTEST_" + User.ToString() + ".bak"; Server srv = new Server(SqlInstance); dbBackup.Action = BackupActionType.Database; dbBackup.Database =

What's the best way to detect the presence of SMO?

有些话、适合烂在心里 提交于 2020-01-01 10:53:14
问题 I have some code that uses SMO to populate a list of available SQL Servers and databases. While we no longer support SQL Server 2000, it's possible that the code could get run on a machine that SQL Server 2000 and not have the SMO library installed. I would perfer to check for SMO first and degrade the functionality gracefully instead of blowing up in the user's face. What is best way to detect whether or not SMO is available on a machine? Every example that I have seen through a quick Google