*****BLOCK_1****
if( strcmpi(appName.c_str(),MSSQL)==0 ||strcmpi(appName.c_str(),MSSQL2005)==0 )
{
if (FAILED(CoCreateInstance (CLSID_SQLDMOServer, NULL, CLSCTX_INPROC_SERVER,
IID_ISQLDMOServer, (LPVOID*)&m_pSQLServer))) {
DMOAvailable=false;
IDiscoverPtr pICalc;
HRESULT hRes=CoCreateInstance(Test::CLSID_SqlClass, NULL, CLSCTX_INPROC_SERVER,Test::IID_IDiscover, reinterpret_cast<void**> (&pICalc));
if(FAILED(hRes))
{
cout << "CoCreateInstance Failed on CLSID_SQLDMOServer\n";
return FALSE;
}
***BLOCK_2***
if((strcmpi(appName.c_str(),MSSQL2008)==0 || strcmpi(appName.c_str(),MSSQL2005)==0 ) && DMOAvailable==false )
{
HRESULT hr=CoInitialize(NULL);
IDiscoverPtr pICalc(__uuidof(SqlClass));
if(FAILED(CoCreateInstance(Test::CLSID_SqlClass, NULL, CLSCTX_INPROC_SERVER,
Test::IID_IDiscover, reinterpret_cast<void**> (&pICalc))))
{
cout<<" Loading SQLSMO failed This is because of SMO not Available "<<endl;
return FALSE;
}
}
*****BLOCK_3 ****
if((strcmpi(appName.c_str(),MSSQL2008)==0 && DMOAvailable==true))
{
HRESULT hr= CoInitialize(NULL);
cout<<"\nIn Init SqlServer DMO-true and SQL2008"<<endl;
HRESULT hRes=CoCreateInstance(Test::CLSID_SqlClass, NULL, CLSCTX_INPROC_SERVER,
Test::IID_IDiscover, reinterpret_cast<void**> (&pICalc));
if(FAILED(hRes))
{
printf(" Loading SQLSMO failed This is because of SMO not Available 0x%X\n",hRes)
return FALSE;
}
else
cout<<success;
}
return TRUE;
}
I have prepared the Test.dll in c# and in that i have a an interface IDiscover and a class SqlClass implementing that interface.I have Manually assigned the Guid like this
[System.Runtime.InteropServices.Guid("D4660088-308E-49fb-AB1A-77224F3FF851")]
public interface IDiscover
{
string getSqlInstances(string HostName);
string getDB(string SQLInstanceName);
string getDatabaseInfo(string SQLInstanceName, string DBName);
};
namespace Test
{
[System.Runtime.InteropServices.Guid("46A951AC-C2D9-48e0-97BE-91F3C9E7B065")]
public class SqlClass:IDiscover
{
}
}
I also make COMVisible=true;
and register the class using RegAsm.exe Test.dll/tlb:Test.tlb /codebase
and imported the tlb in one cpp file as #import c:...\Test.tlb named_guids
This is working fine in my Machine And also in My virtual Machine for any case.if i gave sql2005 it works and i gave sql2008 it working. and in some other machine it shows that errror code as 0x80004002 only when entering into 3rd block.if it enters 1st block and 2nd block its working fine in other machine also.what happening in 3rd block i am not understanding plzzzzzzzz help me in this regard...
Sharptooth u can plzz go through this one .....