I am trying to use the SMO for Sql Server 2008 R2 Standard, but I am running into an issue whenever I try to Dump
an object.
The relevant code:
void Main()
{
var connectionString = @"Server=(local);Trusted_Connection=True;";
Server server = new Server(new ServerConnection(new SqlConnection(connectionString)));
server.ConnectionContext.Connect();
server.Dump(); //Error
Database database = new Database(server, "master");
database.Refresh();
database.Dump(); // Error
IEnumerable<Table> tables = database.Tables.Cast<Table>();
tables.Dump(); //Error
}
Edit:
A work around that I found is to use the Dump
method with a fixed recursion depth e.g. Dump(1)
, but the exception is at a different level for each object.
What's happening is that the act of calling GetEnumerator on one of the SMO object properties is throwing an exception and LINQPad responds by dumping only that exception, rather than the rest of the object graph.
I consider this a bug in LINQPad and so have fixed it for the next beta build.
However, even with this fixed, you'll find that calling Dump() on a SMO object will take forever because it has so many properties that take ages to enumerate. So you'll have to either limit the recursion depth, or call Dump(true) which is equivalent to clicking the 'Results to DataGrids' button. Dumping results to data grids avoids the problem because the grids render data lazily.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With