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