Search code examples
c#sql-servervisual-studiossissmo

SMO syntax in C#


I am trying to use Microsoft.SqlServer.Management.Smo to extract server values in C#. I'm having difficulty with the syntax.

Server server = new Server(new ServerConnection { ConnectionString = new SqlConnectionStringBuilder { DataSource = @"localhost", IntegratedSecurity = true }.ToString() });
Dts.Variables["User::test"].Value = server.AuditLevel____??_____;

Trying to use the Server.AuditLevel:

https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.server.auditlevel.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

Could someone provide an exable using both "get" and "set"?


Solution

  • Following code worked

    Dts.Variables["User::test"].Value = Convert.ToInt32(server.AuditLevel);
    

    The Microsoft.SqlServer.Management.SqlEnum reference needs to be added as well.