C# SMO Database do not log creation
Asked Answered
C

1

11

I have an integration test that creates a database of type Microsoft.SqlServer.Management.Smo.Database:

var defaultConnectionConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
var sqlConnection = new SqlConnection(defaultConnectionConnectionString);
var serverConnection = new ServerConnection(sqlConnection);
 _server = new Server(serverConnection);
 _database = new Database(_server, _integrationTestingDatabaseName);
 _database.Create();

When I run the integration test via the CLI for NUnit, when the test finishes, the SQL for creating the database is dumped to the console. This clutters up the output and is not something I want to see when running this integration test. How can I stop this from happening?

Claudicant answered 14/8, 2017 at 17:15 Comment(2)
When I run the above in a console application (VS2015/Smo 12.0), I don't get any SQL output. Are you also seeing the same behaviour in a console application ? Is this happening ONLY when running with NUnit CLI ? In fact, for me, I would like to see the generated SQLs logged ! Also, what is your version of Smo assembly ?Litigant
Are you planning on answering the questions above?Waldrup
C
3

This is a goose chase and cannot be reproduced.

I'm guessing there maybe some confusion, perhaps one of your scripts does a SQL Print or some red-herring like that. Because executing this Unit Test to create a SQL dB via Sql Management Objects does not output the SQL Creation script.

enter image description here

Even executing directly from the Command Line doesn't log the SQL creation script. Here is the repro:

using NUnit.Framework;
using ConsoleApplication1;
using System.IO;
using System.Diagnostics;

[TestFixture]
public class UnitTest1
{    
    static FileStream objStream;

    [SetUp]
    public static void Setup()
    {
        objStream = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\AAA_Output.txt", FileMode.OpenOrCreate);
        TextWriterTraceListener objTraceListener = new TextWriterTraceListener(objStream);
        Trace.Listeners.Add(objTraceListener);
        Trace.WriteLine("===================================");
        Trace.WriteLine("App Start:" + DateTime.Now);
        Trace.WriteLine("===================================");
    }

    [TestCase]
    public void TestMethod1()
    {
        Program.CreateDB();
    }

    [TearDown]
    public static void TearDown()
    {
        Trace.Flush();
        objStream.Close();
    }
}

Results:

enter image description here

Camellia answered 11/9, 2017 at 3:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.