How to use com libraries for SQLSERVERSMO?

I have created a com library with which I can open SQLVolumes using the SMo namespace in VS2005. Now I want to use this com library in VS2003 to open the same sqlvolumes on another machine where vs2003 is installed.

Can I use it like this? I created COM using VS2005 version and now I want to use it in VS2003, is it possible?

I ask you that people do not mark this as a duplicate because I need an effective answer.

using System;

using System.Data.SqlClient;

using Microsoft.Win32;

using Microsoft.SqlServer.Management.Smo;

using Microsoft.SqlServer.Management.Common;

using System.Data;

public interface ICalculator

{

 void Show();

};

namespace ManagedDLL
{
    public class ManagedClass : ICalculator
    {

        public void Show()
        {

            Console.WriteLine("from managed class");
            Console.WriteLine("c# "); Console.WriteLine("c#");
            DataTable dt = new DataTable();
            string srvname,filepath; 

            //evaluates local instances of SQLSERVER
            dt = SmoApplication.EnumAvailableSqlServers(true);
            Console.WriteLine("Local Instances are \n");
            foreach (DataRow dr in dt.Rows)
                Console.WriteLine(dr["Name"]);

            foreach (DataRow dr in dt.Rows)
            {
                srvname = (string)dr["name"];

                Console.WriteLine("\nConnecting to Server " + srvname + "\n\nDiscovering Volumes...\n\nDiscovering Sql2005 Volumes for the Host " + srvname.ToLower() + "\n");
                Console.WriteLine("\nHostName   : " + srvname.ToLower() + "\n");
                Server srv = new Server(srvname);
                Console.WriteLine(" Server Name \n" + srv.Name);
                foreach( Database db in srv.Databases)
                {
                    filepath = db.PrimaryFilePath;
                    Console.WriteLine("File Path : " + filepath + "\\" + db.Name + ".mdf \n");
                    Console.WriteLine("File Path : " + filepath + "\\" + db.Name + ".ldf \n");
                }


            }//foreach


        }
    }

}

      

I created a com library for this class and I have to use this com library in vs2003 and one more thing is the smo namespace.

The above code is not supported by .net f / w 1.1. How can I do it?

When consumed, I get the following error:

Unhandled Exception at 0x7c812a6b in Comssss.exe: Microsoft C ++ Exception: _com_error @ 0x0012fcbc.

0


a source to share


2 answers


Yes, if you have .net 2 runtime set, VS2003 COM compatibility should work fine.



Do you have a specific problem? If so, can you tell us about the problem you are experiencing?

0


a source


You cannot load two versions of a framework into the same process. VS2003 already uses .NET 1.1, so you won't be able to load a COM component in proc that needs .NET 2.0.



You might be able to use DCOM and not execute it.

0


a source







All Articles