×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

URGENT!!!!VB -6 application talking to MTS

URGENT!!!!VB -6 application talking to MTS

URGENT!!!!VB -6 application talking to MTS

(OP)
Hi
thanx alot to ChipH and Sunrise for their help.
Question to the group.
I have a vb-6 program which is talking to MTS
Now when i create an object of MTS component to get the result of simple select query
it gives me a "Switch To - Retry" dialog box saying, the other application is busy..chosse switch to to activate the application.
if the reqult is less than 100 rows, it comes after 5-10 times clicking Switch to, but say for rows in thousands, i justkeep on clicking Switch to, and it never ends.
Same thing i try from ASP , it works.
Does someone have an idea, why it is happening like this and i can i avoid this

Pl. respond as quickily as possible

Thanx and Regards,
Shuchi

RE: URGENT!!!!VB -6 application talking to MTS

What happens when you run the query in Query Analyzer?  Also, once it's in Query Analyzer, hit Ctrl+L to show the execution plan.  Are there any table scans?  Is it possible that your query is doing a cross product (typically the result of a poorly-planned Join)?

Chip H.

RE: URGENT!!!!VB -6 application talking to MTS

(OP)
Hi ChipH
Thanx for responding Again
No, my query is not very complex .
And even in case of simple select query from single table , it gives me "switch to" dialog box"
I think, there is some some problem while connecting it to MTS.
When i run a query, with say result upto 50-60 rows. It runs perfectly.Whne i try to run more heavy query - ( 200 rows). It gives me "Switch to" box. But when i run the second query(200 rows) after the first one , both the query run fine. But again for heavier queries with rows in thousands, this same problem occurs, even if i run this after the first one ( my query id single table select query in all the three cases.

( hoping for a quick response)
Thanx and Regards
Shuchi

RE: URGENT!!!!VB -6 application talking to MTS

Could you post a sample of your query?

Also, please post a (short!) sample of your ADO code that you're using to run the query.

Chip H.

RE: URGENT!!!!VB -6 application talking to MTS

(OP)
I am extremely thankful to u that u r taking so much pains to solve my problem but at the same time i am really sorry that i am giving u a long piece of code. I tried to cut it short as much as possible but couldn't do much as i thought u must go thru atleast this much of code to understand it.

Thanx alot agian
Hoping for a quick response..

Here it is
My vb code is creating an instance of GenMastMaint(MasterMaintenence MTS object).
PrintTable is the method of GenMastMaint and it is creating an instance of another MTS component ADOClass(database component)
My client machine has all the MTS components registered on it thru the exe which gets created on MTS server when u export the package

VB Code:
Dim obj as GenMastMaintInt 'interface of the component'
set obj = new GenMastMaintInt 'GIVES ME A SWTICH TO DIALOG BOX HERE BUT GOES OFF AFTER CLICKING 2-3 times
result = obj.PrintTable("tablename",arrayofcolumnstobedisplayed,resultarray) 'GIVES ME A "PERMANENT SWITCH TO" Dialog Box
'display of values using loop

GenMastMaint.PrintTable Code (VC++)
//Decalrations
Creating an object of ADOClass
IADOClassInt *p = NULL;    
hr = m_spObjectContext->CreateInstance(CLSID_ADOClassInt,IID_IADOClassInt,(void**)&p);

\\code to get the values of passed columns and store in a char. array
try
    {
        OutputDebugString("GenMastMaintInt:PrintTable:Entering Method PrintTable");

    if(vColumns->vt & VT_BYREF)
    {
        psaCol = *(vColumns->pparray);
    }
    else
    {
        psaCol = vColumns->parray;
    }

    //check the dimension of array if invalid then return the error
    if(SafeArrayGetDim(psaCol) !=1)
    {
        TESTHR(E_INVALIDARG);
    }

    //get the lower and upper bounds
    SafeArrayGetLBound(psaCol,1,&lLbound);
    SafeArrayGetUBound(psaCol,1,&lUbound);

    //compute the number of elements
    cElements = lUbound - lLbound + 1;
    OutputDebugString("outside for loop");
//access the elements of the array and store in char array
    for(cCnt = lLbound;cCnt <= lUbound; cCnt++)
    {
        OutputDebugString("inside for loop");
        VARIANT vVal;    
        SafeArrayGetElement(psaCol,&cCnt,&vVal);        
        OutputDebugString("after get element");
        bval=vVal.bstrVal;
        //Code for initializing the key value
        OutputDebugString("before widechar");
******in this method the control stops here***refer to note at the end

iretval = WideCharToMultiByte(CP_ACP,0,bval,-1,sColumns[cCnt],sizeof(sColumns[cCnt]),NULL,NULL);
OutputDebugString("value of columns array-- ");
OutputDebugString(sColumns[cCnt]);

::SysFreeString(bval);
}//loop end

lretval = fnGetdbinfo(szdsnname,szdbname,szusername,spwd);

     
//opening the connection
TESTHR(p->Open(sdsnname, susername,spwd));
        nOpen = 1;        

iretval = WideCharToMultiByte(CP_ACP,0,bTablename,-1,cTablename,sizeof(cTablename),NULL,NULL);
OutputDebugString("value of variable cTablename");
OutputDebugString(cTablename);
        
wsprintf(sQuery,"select rows from sysindexes where id = OBJECT_ID('%s') and indid <2",cTablename);
        
OutputDebugString("value of query to get rows");
OutputDebugString(sQuery);
******************in another method code stops here********
p->OpenRecordset(sQuery);
    
***Note***
i created another method having exactly the same code but eliminated the 2nd parameter( columns to display). this method simply takes the table name and return all the rows.

But in this method the control stops just before OpenRecordset of ADOClass( mentioned above)

ADOClass Code:
ADOClass.Open
STDMETHODIMP CADOClassInt::Open(BSTR source, BSTR user, BSTR pwd)
{
    // TODO: Add your implementation code here

    /*****************************/
    HRESULT hr;
    void *pMsgBuf;
//    char cBuf[100];
    char csource[20],cuser[20],cpwd[20];
    int iretval;

    memset(csource,'\0',20);
    memset(cuser,'\0',20);
    memset(cpwd,'\0',20);

    //IITPEvtLogObj *p1 = NULL;

    try
    {

    hr = S_OK;
    OutputDebugString("ADOTierCls::Open:entered the open function");
    //conversions
    iretval = WideCharToMultiByte(CP_ACP,0,source,-1,csource,sizeof(csource),NULL,NULL);    
    iretval = WideCharToMultiByte(CP_ACP,0,user,-1,cuser,sizeof(cuser),NULL,NULL);    
    iretval = WideCharToMultiByte(CP_ACP,0,pwd,-1,cpwd,sizeof(cpwd),NULL,NULL);    
    
    OutputDebugString("ADOTierCls::Open:after the conversions to multibyte");

    OutputDebugString("ADOTierCls::Open:before creating the connection object");
    
    //HRESULT hr = m_connection.CreateInstance("ADODB.Connection.2.1");
     hr = m_connection.CreateInstance(__uuidof(Connection));
      // m_spObjectContext->CreateInstance(__uuidof(Connection), __uuidof(_Connection),
                                       //  (void**)&m_connection);
    OutputDebugString("ADOTierCls::Open:after connection of main connection");
    if (SUCCEEDED(hr))
    {
        //correct
        //_bstr_t ssource("driver={SQL Server};server=ndl_frc_ntd03;uid=itpuser;pwd=itpuser;database=itpdb");
        
        char query[255];
        BSTR ssource;

        OutputDebugString("ADOClass :Open: initializing the query ");

        //working 1
        wsprintf(query,"DSN=%s;UID=%s;PWD=%s;",csource,cuser,cpwd);

        ssource=(BSTR) (_bstr_t) query;
        
        OutputDebugString("ADOClass :Open: Before opening the Data connection with DSN--");
        
        m_connection->Open(ssource,NULL,NULL,adCmdUnspecified);
        //m_connection->Open(ssource,NULL,NULL);

        OutputDebugString("ADOClass :Open: After opening the Data connection with DSN");

        
        OutputDebugString("ADOTierCls::Open:DBConnection successfully opend");

        //deallocating
        ::SysFreeString(ssource);
        
        mExcStatus = 0;

    }
    if (SUCCEEDED(hr))
    {
        hr = m_command.CreateInstance(__uuidof(Command));
    //    hr = m_command.CreateInstance("ADODB.Command.2.1");
    //    m_spObjectContext->CreateInstance(__uuidof(Command), __uuidof(_Command),
                                     //    (void**)&m_command);
        OutputDebugString("ADOTierCls::Open:Command object successfully created");
    }
    else
    {
        ::FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,NULL,
            hr,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&pMsgBuf,0,NULL);
        OutputDebugString((LPTSTR)pMsgBuf);
        LocalFree(pMsgBuf);        

    }        
    if (SUCCEEDED(hr))
    {
        hr = m_command->putref_ActiveConnection(m_connection);
        OutputDebugString("ADOTierCls::Open:Active connection successfully opend");
    }
    
    if (SUCCEEDED(hr))
    {
        hr = m_recordset.CreateInstance(__uuidof(Recordset));
        //m_spObjectContext->CreateInstance(__uuidof(Recordset), __uuidof(_Recordset),
                                        // (void**)&m_recordset);
        OutputDebugString("ADOTierCls::Open:REcordset successfully created");
    }
    else
    {
        ::FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,NULL,
            hr,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&pMsgBuf,0,NULL);
        OutputDebugString((LPCTSTR)pMsgBuf);
        LocalFree(pMsgBuf);
    }
    }//try

ADOClass.OpenRecordset:
STDMETHODIMP CADOClassInt::OpenRecordset(VARIANT query)
{

    VARIANT v;
    V_VT(&v) = VT_DISPATCH;
    V_DISPATCH(&v) = (IDispatch*) m_connection;

    // Need the AddRef() as VariantClear() calls Release(), unless fAddRef
    // false indicates we're taking ownership
    //
    V_DISPATCH(&v)->AddRef();

    //return m_recordset->Open(query, v, adOpenDynamic, adLockOptimistic, adCmdText);
    return m_recordset->Open(query, v, adOpenStatic, adLockReadOnly, adCmdText);
}

RE: URGENT!!!!VB -6 application talking to MTS

Hello Shuchi,
          I am also getting similar error with MTS.  If you had found a solution, can pls tell that.

Thanks in advance,
Murali

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close