smo

Cleaning up after calls to SMO Server and Database

ⅰ亾dé卋堺 提交于 2020-01-01 10:14:22
问题 How do you make SMO release it's connections? I have this code: public static class SqlServerConnectionFactory { public static Server GetSmoServer() { using (var c = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString)) { var s = new ServerConnection(c); c.Close(); return new Server(s); } } public static Database GetSmoDatabase(Server server) { var db = server.Databases[ConfigurationManager.AppSettings["Database"]]; db.AutoClose = true; return db; }

SQL SMO To Execute Batch TSQL Script

*爱你&永不变心* 提交于 2020-01-01 05:37:07
问题 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

Using SQL Alchemy and pyodbc with IronPython 2.6.1

元气小坏坏 提交于 2019-12-30 05:27:06
问题 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

LocalDb and SMO - how to choose where to put database files?

梦想与她 提交于 2019-12-25 05:59:14
问题 I've started to experiment with the SQL Server 2012 feature LocalDb. I'm doing some powershell scripting with SMO against the instances I create, such as creating databases. To do this, I have this function: Function New-Database { Param( $server, $databaseName ) $serverHandle = New-Object Microsoft.SqlServer.Management.Smo.Server($server) if($serverHandle.Databases.Name.Contains($databaseName)) { throw "Database $databaseName already exists" } $databaseHandle = New-Object Microsoft.SqlServer

LocalDb and SMO - how to choose where to put database files?

时光怂恿深爱的人放手 提交于 2019-12-25 05:58:30
问题 I've started to experiment with the SQL Server 2012 feature LocalDb. I'm doing some powershell scripting with SMO against the instances I create, such as creating databases. To do this, I have this function: Function New-Database { Param( $server, $databaseName ) $serverHandle = New-Object Microsoft.SqlServer.Management.Smo.Server($server) if($serverHandle.Databases.Name.Contains($databaseName)) { throw "Database $databaseName already exists" } $databaseHandle = New-Object Microsoft.SqlServer

Reduce file size with DotNetZip

ぃ、小莉子 提交于 2019-12-25 04:32:33
问题 I want to backup my database using SMO and zip a backup file then upload it to my server. here is my code // Backup var conn = new SqlConnection(sqlConnectionString); var server = new Server(new ServerConnection(conn)); var backupMgr = new Backup(); backupMgr.Devices.AddDevice(file.FullName, DeviceType.File); backupMgr.Database = dictionary[StringKeys.Database]; backupMgr.Action = BackupActionType.Database; backupMgr.SqlBackup(server); // Compress using (var zip = new ZipFile()) { zipFile =

How do I script procedures when generating a script with the SMO scripter?

邮差的信 提交于 2019-12-25 01:46:43
问题 I am trying to write a Powershell script to generate a SQL script that creates the stored procedures in my database. Here is what I have: [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO')| out-null Function to-array ($c) { foreach($item in $c) { $result += @($item) } $result } $s = new-object ('Microsoft.SqlServer.Management.Smo.Server') "LOCALHOST" $scrp = new-object ('Microsoft.SqlServer.Management.Smo.Scripter') ($s) $dbs = $s.Databases $fa = $dbs["FinancialAid"]

C# SMO Select from Database

旧城冷巷雨未停 提交于 2019-12-24 19:08:28
问题 I have been racking my brain trying to figure out how to execute a SELECT from Table using SMO in C# and returning that value to a string item. I have seen multiple posts of how I can run a SQL script from within C# which is not what I want to do. Here is the code I have so far public static void GetDealerInfo() { Server databaseServer = new Server(dbServer); try { databaseServer.ConnectionContext.LoginSecure = dbSecure; databaseServer.ConnectionContext.Login = dbUser; databaseServer

Direct access to full string representation of object

◇◆丶佛笑我妖孽 提交于 2019-12-24 08:48:35
问题 I am trying to log the contents of an object to a text file. If I do a debug.print of the object itself in the immediate window, it prints all of the values of the object's properties: ?mDb.DatabaseOptions {Microsoft.SqlServer.Management.Smo.DatabaseOptions} AnsiNullDefault: False ... UserData: Nothing However, I can't seem to access this as a string in code due to a type mismatch. I assumed I could get this information using the .ToString method, but all that returns is the object

Using reflection to mimic Debug.Print in VB.Net

雨燕双飞 提交于 2019-12-24 08:34:42
问题 Follow up to Direct access to full string representation of object. I am trying to log the contents of an object to a text file. I can get the property-value pairs I want to log by executing this line in the immediate window: ?mDb.DatabaseOptions {Microsoft.SqlServer.Management.Smo.DatabaseOptions} AnsiNullDefault: False ... UserData: Nothing Unfortunately, I can't simply log mDb.DatabaseOptions.ToString because that does not return any of the property-value pairs. I tried to roll my own code