smo

Using Smo.Backup to backup SQL Server database to string

偶尔善良 提交于 2019-12-10 10:55:00
问题 I'm trying to make a little app that would help me making my server backup. That app would run on my home PC so the main goal is to be able to connect to the external server, backup the selected database, dump the backup content to a string or something so I could write it on my PC disk and not the server's disk. I did that which works to write on the server's disk, but I'd like to be able to write on my PC's disk the backup's result. private bool BackupDatabase() { try { // Filename string

Get Sql server's data using smo

久未见 提交于 2019-12-09 00:46:50
问题 I'm using Sql Server Smo to create the scheme of database by C# application. However, I need a bit more, I also need to get data from each table as a script like below: --........................................ INSERT INTO Table123 (...) VALUES (....) INSERT INTO Table456 (...) VALUES (....) --........................................ How can I do that and is it possible? Notice please that I need to create exactly a script using smo and not *.bak of a database, etc. 回答1: Have a look at SMO's

C# SMO backup of remote database to local machine

戏子无情 提交于 2019-12-08 15:24:48
问题 I have an application which performs backups and restores of SQL databases, this works fine on the local machine, however if I run this against a SQL server hosted on another machine I get the following error Microsoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server '25.98.30.79'. ---> Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException:

Display progress while restoring database in linqpad with reative extensions

泄露秘密 提交于 2019-12-08 07:26:55
问题 I have the following C# code. var databaseRestore = new Microsoft.SqlServer.Management.Smo.Restore(); //databaseRestore.PercentComplete += CompletionStatusInPercent; //databaseRestore.PercentCompleteNotification = 10; //databaseRestore.Complete += Restore_Completed; ... var complete = Observable .FromEventPattern(databaseRestore, "Complete") .Select(x=>x.EventArgs as ServerMessageEventArgs) .Select(x=>x.Error.Message) .Take(1) .DumpLive("Complete"); var percentComplete = Observable

Need reference code for SMO in C# SQL Server 2008

淺唱寂寞╮ 提交于 2019-12-08 07:02:49
问题 I googled but cannot find proper simple code for using backup database full and restore the backup, using defaults by using C#. I am using C# Visual Studio 2008 and SQL Server 2008 R2 evalution but I guess SQL Server 2005 and C# will work too. The Microsoft site doesn't have code regarding it, it only show description of Microsoft.SqlServer.Management.Smo Namespace...... 回答1: MSDN has a topic Getting Started in SMO that covers a lot of ground - there's also a topic called Programming Specific

Good book to learn Server Management Objects (SMO) for C# and SQL Server 2008? [closed]

 ̄綄美尐妖づ 提交于 2019-12-07 11:55:28
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Am familiar with TSQL and C#, and would like to read a good book/tutorial on how to use Server Management Objects (SMO) with C# and

SSMS SMO Objects: Get query results

落花浮王杯 提交于 2019-12-07 11:37:53
问题 I came across this tutorial to understand how to execute SQL scripts with GO statements. Now I want to know what can I get the output of the messages TAB. With several GO statements, the output would be like this: 1 rows affected 912 rows affected ... But server.ConnectionContext.ExecuteNonQuery() can return only an int, while I need all the text. In case there is some error in some part of query, it should put that also in the output. Any help would be appreciated. 回答1: The easiest thing is

Problem in creating User in SqlServer using smo

删除回忆录丶 提交于 2019-12-07 11:19:48
问题 1) If there is already a login 'user1' then I create a user 'user1' for database 'db1' by calling CreateDatabaseUser function 2) Else, I create a login 'user1' with password 'password1' with default database as 'db1' (only after creating db1) using CreateServerLogin and then I create user 'user1' for 'db1' using CreateDatabaseUser Method (2) throws an exception at newUser.Create(); in CreateDatabaseUser saying, Microsoft.SqlServer.Management.Smo.FailedOperationException: Create failed for

Using SMO to script PARTIAL data content (only rows matching a WHERE clause)

偶尔善良 提交于 2019-12-07 09:32:25
I use SMO to fill a SQL Compact database with the data of a SQL server database. Here is the code I actually use: foreach(Table l_tblCurrent in l_dbDatabase.Tables) { if(l_tblCurrent.IsSystemObject) continue; ScriptingOptions l_scOptions = new ScriptingOptions(); l_scOptions.NoIdentities = true; l_scOptions.NoCollation = true; l_scOptions.NoCommandTerminator = true; l_scOptions.NoFileGroup = true; l_scOptions.ScriptSchema = true; l_scOptions.ScriptData = true; foreach(string l_strCurrent in l_tblCurrent.EnumScript(l_scOptions)) { l_sccDBFCommand.CommandText = l_strCurrent.Replace("[dbo].", "")

How to test connection to a data source in SSAS using C#

走远了吗. 提交于 2019-12-07 08:44:38
问题 I have a database in Analysis Services on a remote server. This contains a data source for another database located on another remote server. I am trying to write a connectivity test using C# which will check the database connection between the two databases. I have been unable to do this using ADOMD.NET. I'm currently looking at using SMO to do this but I haven't had any luck so far. I would greatly appreciate any advice or suggestions. Update: After further research, I have come up with the