Quantcast
Channel: SCN : Discussion List - SAP Crystal Reports, version for Visual Studio
Viewing all articles
Browse latest Browse all 3636

"Log on failed" with ODBC and Stored Procedure

$
0
0

I am in the process of porting our application from CR10 to CR.NET and am having some trouble setting the log on info.

 

I have a report that was designed against a stored procedure and a development database.  The connection at design time is ODBC to a SQL Server.  At runtime I want to set the database and logon credentials to that of the production server, set the stored procedure parameters, and then display the report.  No matter what I do always get "Log on failed" error.

 

After having considerable trouble with ApplyLogOnInfo on the tables where it seemed to not actually apply my changes, I finally found code which appeared to work elsewhere on this forum.  So this is the code that I have now, but the call to VerifyDatabase on the report always throws the Log on Failed exception:-

 

void SomeClass::SetLogOnInfoForReportRecursively(ReportDocument^ ReportObj)

{

        CrystalDecisions::Shared::TableLogOnInfo^ l_pTableLogOnInfoToSet = gcnew CrystalDecisions::Shared::TableLogOnInfo();

        CrystalDecisions::Shared::ConnectionInfo^ l_pConnectionInfo = l_pTableLogOnInfoToSet->ConnectionInfo;

       

        l_pConnectionInfo->AllowCustomConnection = true;

        l_pConnectionInfo->ServerName = gcnew String(m_strServerName);

        l_pConnectionInfo->DatabaseName = gcnew String(m_strDatabaseName);

        l_pConnectionInfo->UserID = gcnew String(m_strUserID);

        l_pConnectionInfo->Password = gcnew String(m_strPassword);

 

        DbConnectionAttributes^ l_pConnectionAttributes = gcnew DbConnectionAttributes();

        l_pConnectionAttributes->Collection->Set("Database DLL", "crdb_odbc.dll");

        l_pConnectionAttributes->Collection->Set("QE_DatabaseName", String::Empty);

        l_pConnectionAttributes->Collection->Set("QE_DatabaseType", "ODBC (RDO)");

        l_pConnectionAttributes->Collection->Set("QE_SQLDB", true);

        l_pConnectionAttributes->Collection->Set("SSO Enabled", false);

 

        l_pConnectionInfo->Attributes = l_pConnectionAttributes;

       

        //main connection

        ReportObj->SetDatabaseLogon(l_pConnectionInfo->UserID, l_pConnectionInfo->Password, l_pConnectionInfo->ServerName, l_pConnectionInfo->DatabaseName, false);

       

        //other connections

        for each(CrystalDecisions::Shared::IConnectionInfo^ pConnection in ReportObj->DataSourceConnections)

        {

            pConnection->SetConnection(l_pConnectionInfo->ServerName, l_pConnectionInfo->DatabaseName, l_pConnectionInfo->UserID, l_pConnectionInfo->Password);

            //pConnection->SetLogon(l_pConnectionInfo->UserID, l_pConnectionInfo->Password);

            pConnection->LogonProperties->Set("Data Source", l_pConnectionInfo->ServerName);

            pConnection->LogonProperties->Set("Initial Catalog", l_pConnectionInfo->DatabaseName);

        }

 

        // Now we need to set the log on info for any subreports otherwise they will always look for the datasource they were set up with.

        if (!ReportObj->IsSubreport)

        for each (ReportDocument^ l_pSubReport in ReportObj->Subreports)

             SetLogOnInfoForReportRecursively(l_pSubReport);

       

 

 

        for each (CrystalDecisions::CrystalReports::Engine::Table^ l_pTable in ReportObj->Database->Tables)

        {

            TableLogOnInfo^ l_pCurentTableLogOnInfo = l_pTable->LogOnInfo;

            l_pCurentTableLogOnInfo->ConnectionInfo = l_pTableLogOnInfoToSet->ConnectionInfo;

 

            l_pTable->ApplyLogOnInfo(l_pCurentTableLogOnInfo);

            if (!l_pTable->TestConnectivity())

            {

               // handle error situation

            }

        }

}

 

... then the calling code

SetLogOnInfoForReportRecursively( pReportObj );

// l_Parameters contains the stored proc param name/values pairs to set at runtime

for each (KeyValuePair<String^, String^> param in l_Parameters)

        pReportObj->SetParameterValue(param.Key, param.Value);

       

pReportObj->VerifyDatabase();

 

which then fails.  Can anyone see what I am doing wrong?

 

Thanks


Viewing all articles
Browse latest Browse all 3636

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>