smo

SMO: restoring to a different DB

萝らか妹 提交于 2019-12-02 00:55:17
问题 I've read a dozen different blogs, as well as reading through the msdn examples and they just aren't working for me. Ultimately what I'm trying to do is automate moving a DB from our production instance to our dev instance, or the other direction. The approach I've taken is thus: backup/restore to a temp DB detach temp DB copy mdf and ldf files to the other instance reattach. I'm stuck on 1 and I cannot understand why. Everything I've read claims this should be working. NOTE: I've set dbName

EnumAvailableSqlServers returns empty list

我的未来我决定 提交于 2019-12-01 23:48:40
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 server.Databases DoSomething(db.name) Next Does return the installed databases on both machines. I have

SMO: restoring to a different DB

两盒软妹~` 提交于 2019-12-01 20:48:49
I've read a dozen different blogs, as well as reading through the msdn examples and they just aren't working for me. Ultimately what I'm trying to do is automate moving a DB from our production instance to our dev instance, or the other direction. The approach I've taken is thus: backup/restore to a temp DB detach temp DB copy mdf and ldf files to the other instance reattach. I'm stuck on 1 and I cannot understand why. Everything I've read claims this should be working. NOTE: I've set dbName to the db I want to restore to. I have also set restore.Database = dbName , where restore is an

Backup Class Not Showing in Microsoft.SqlServer.Management.Smo Reference

一笑奈何 提交于 2019-12-01 08:14:33
问题 I want to add Backup and Restore Functionality in C# Windows Form Application. for this i inserted Microsoft.SqlServer.Management.Smo reference in my code.. but I can't see the Backup and Restore classes in this reference. 回答1: I found the answer by my self. and that is for using Backup and restore class of SMO we need to 5 reffereces. Go to Your Application and Right Click on References folder and select Add Reference. Now Go to "Browse" Tab and browse the following path- C:\Program Files

How to get the table a foreign key refers to

▼魔方 西西 提交于 2019-12-01 05:41:27
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 } } BFree 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("Column: {0} is a foreign key to Table: {1}",column.Name,key.ReferencedTable); } } EDIT: Small change. In

Can't immediately connect to newly-created SQL Server database

三世轮回 提交于 2019-12-01 03:53:54
I'm creating a database using SQL Server Management Objects . I wrote the following method to generate a database: public static void CreateClientDatabase(string serverName, string databaseName) { using (var connection = new SqlConnection(GetClientSqlConnectionString(serverName, String.Empty))) { var server = new Server(new ServerConnection(connection)); var clientDatabase = new Database(server, databaseName); clientDatabase.Create(); server.ConnectionContext.Disconnect(); } } Shortly thereafter, I call another method to execute a SQL script to generate tables, etc.: public static void

Can't immediately connect to newly-created SQL Server database

烈酒焚心 提交于 2019-11-30 23:54:54
问题 I'm creating a database using SQL Server Management Objects. I wrote the following method to generate a database: public static void CreateClientDatabase(string serverName, string databaseName) { using (var connection = new SqlConnection(GetClientSqlConnectionString(serverName, String.Empty))) { var server = new Server(new ServerConnection(connection)); var clientDatabase = new Database(server, databaseName); clientDatabase.Create(); server.ConnectionContext.Disconnect(); } } Shortly

Using SQL Alchemy and pyodbc with IronPython 2.6.1

☆樱花仙子☆ 提交于 2019-11-30 16:40:17
I'm using IronPython and the clr module to retrieve SQL Server information via SMO. I'd like to retrieve/store this data in a SQL Server database using SQL Alchemy, but am having some trouble loading the pyodbc module. Here's the setup: IronPython 2.6.1 (installed at D:\Program Files\IronPython) CPython 2.6.5 (installed at D:\Python26) SQL Alchemy 0.6.1 (installed at D:\Python26\Lib\site-packages\sqlalchemy) pyodbc 2.1.7 (installed at D:\Python26\Lib\site-packages) I have these entries in the IronPython site.py to import CPython standard and third-party libraries: # Add CPython standard libs

smo restore database

时光怂恿深爱的人放手 提交于 2019-11-30 12:09:04
问题 I use SQL Server SMO to restore a .bak to a new database, but failed to work. sql server is 2012 and smo object version is from the latest sdk version 11.0 file .bak was created using sql management studio 2012, same local pc, on the same coding pc as well. The error message I get is: Restore failed for Server 'SERVER'. What's wrong with my code? string dbPath = Path.Combine(@"d:\my data", dbName + "_db" + ".mdf"); string logPath = Path.Combine(@"d:\my data", dbName + "_db" + "_Log.ldf");

How to automate script generation using SMO in SQL Server?

醉酒当歌 提交于 2019-11-30 09:58:31
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? The key to SMO scripting is the Scripter class. All other tools (like SSMS) use this class to generated object creation scripts. There is an example usage on MSDN : { //Connect to the local, default instance of