Search code examples
sql-servervb6.net-2.0smosqldmo

VB6 support for SQL SMO and .Net 2.0


We are trying to move from using SQL DMO to SMO in our COM+ based application, as we are dropping support for SQL Server 2000 and adding support for SQL Server 2008 in addition to SQL Server 2005.

I have been reading around on this, and found this particular quip on this microsoft forum:

"SMO is only supported in VB/C#.Net 2005. It requires the .Net 2.0 Framework, which isn't available in VB/VC 6."

Is it true? Googling in general and googling stackoverflow did not throw up and definitive answers.

Is it possible to implement SQL SMO using VB6?

Edit: I used a COM Wrapper to get around this... check out my answer below for some more details.


Solution

  • Okay I figured out how to do this.

    The problem was that VB6 has no .Net 2.0 support and hence we cannot use SMO with VB6.

    To get around that, I wrote a COM wrapper in C# which uses SMO and maps (mostly) one-to-one with the kind of functionality I want from from my VB app.

    Basically, Create a C# project, add the SMO references as needed, add the following lines above the class declaration to make it COM visible:

    [ComVisible(true)]
    
    [GuidAttribute("{guid here}")]
    
    [ClassInterface(ClassInterfaceType.AutoDual)] // <--- Not recommended, but well...
    

    In the project properties, in the "Build" section, make sure the "Register For COM Interop" box is checked. Compile and import into the VB6 app and you are in business!!

    As is the case with trying to hammer any two different systems together, there will be some manipulations you will need to do with what you pass between the VB6 app and the C# Wrapper... but its not too hard.

    Please comment if you need any more information/details.