SQL DMO Error: System.Runtime.InteropServices.COMException - [SQL-DMO]The passed object is not a SQLDMO object.
Posted on 2006-04-04
I encountering a strange problem (for a change!), when attempting to perfom a SQL Backup using the SQL-DMO objects.
First of all, I must state that I AM able to perform the backup using SQL-DMO, if I instantiate a SQLServer2 object, Connect, and then instantiate a SqlBackup2 object and call SQLBackup Method.
The above works fine without any error.
I then had the (perhaps crazy) idea of creating a couple of user controls to provide the functionality to connect to a SQL Server and perform a backup of a database on that server.
I created 2 user controls: SqlServerConnector & SqlServerBackup.
The first control is used to establish a connection to a SQL Server.
The connected server object (of type SQLDMO.SqlServer2) is then passed to the SqlServerBackup object (via a property).
The second control then uses the passed server object to populate a combo with the available databases on that server (everything working fine up to here).
This second control contains a button, which when pressed prompts for a backup file location and name, and finally calls the SqlBackup method of the SqlBackup2 object, passing it the SqlServer2 object which was connected earlier.
It is at this point that I get the following exception:
System.Runtime.InteropServices.COMException - [SQL-DMO]The passed object is not a SQLDMO object.
I am miffed as to why this is happening, as when I follow the exact same procedure using objects local to a procedure it all works fine.
This indicates to me that the problem is somehow related to storing the object in a property.... but I don't know how or why.
Furthermore, the exception is thrown instantly (unlike in usual scenarios where - when stepping through - there is a slight pause before it goes into the Catch block).
Does anyone out there have any idea what might be causing this, it's starting too really bug me now!!!
Thanks in advance,