Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# SMO Database do not log creation

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?

like image 678
Scotty H Avatar asked Aug 14 '17 17:08

Scotty H


1 Answers

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

like image 179
Jeremy Thompson Avatar answered Oct 08 '22 15:10

Jeremy Thompson