GCCvanDorth
asked on
PrintToPrinter gives LogOnException
Got a VB.NET windows application using a MsAccess database. Some of the reports (CR bundled version) have to be processed in batch mode. I use the PrintToPrinter method, it works fine on my development system but fails with a LogOnException on any other system. The same report can be perfectly previewed and printed (with interaction) by means of the CRViewer. I used the latest merge modules from crystal (BO) and set the connectionInfo for all tables (even in subreports).
What can be wrong?
What can be wrong?
What code are you using? It shouldn't work as you are statig so maybe there is a minor problem with the code.
mlmcc
mlmcc
I think you are missing setting the location property of the tables. If you miss that crystal disregards the connection chnages . Do it this way and it will work.
This code is written in c# so if you need, convert it to vb.net
Regards
Emre
internal static void SetConnection(ref ReportDocument report, string serverName, string databaseName)
{
try
{
CrystalDecisions.Shared.Ta bleLogOnIn fo MyLogonInfo;
foreach(CrystalDecisions.C rystalRepo rts.Engine .Table MyTable in report.Database.Tables)
{
MyLogonInfo = MyTable.LogOnInfo;
if (MyTable.Name == "")
{ MyLogonInfo.ConnectionInfo .ServerNam e = serverName;
MyLogonInfo.ConnectionInfo .DatabaseN ame = databaseName;
MyLogonInfo.ConnectionInfo .UserID = "";
MyLogonInfo.ConnectionInfo .Password= ""; }
else
{
MyLogonInfo.ConnectionInfo .ServerNam e = serverName;
MyLogonInfo.ConnectionInfo .DatabaseN ame = databaseName;
//MyLogonInfo.ConnectionIn fo.AllowCu stomConnec tion = true;
MyLogonInfo.ConnectionInfo .UserID = "";
MyLogonInfo.ConnectionInfo .Password = "";
}
MyTable.Location = MyTable.Location.Substring MyTable.Lo cation.Las tIndexOf(" .")+1);
MyTable.ApplyLogOnInfo(MyL ogonInfo);
}
}
catch( Exception logonInfoException )
{
throw logonInfoException;
}
}
This code is written in c# so if you need, convert it to vb.net
Regards
Emre
internal static void SetConnection(ref ReportDocument report, string serverName, string databaseName)
{
try
{
CrystalDecisions.Shared.Ta
foreach(CrystalDecisions.C
{
MyLogonInfo = MyTable.LogOnInfo;
if (MyTable.Name == "")
{ MyLogonInfo.ConnectionInfo
MyLogonInfo.ConnectionInfo
MyLogonInfo.ConnectionInfo
MyLogonInfo.ConnectionInfo
else
{
MyLogonInfo.ConnectionInfo
MyLogonInfo.ConnectionInfo
//MyLogonInfo.ConnectionIn
MyLogonInfo.ConnectionInfo
MyLogonInfo.ConnectionInfo
}
MyTable.Location = MyTable.Location.Substring
MyTable.ApplyLogOnInfo(MyL
}
}
catch( Exception logonInfoException )
{
throw logonInfoException;
}
}
ASKER
No, I didn't miss the location settings, I missed the CR9.0 service pack of October. It works fine with this package.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The whole stuff works if the database location in development is the same as the database location after deployment.
So if the database position will become "C:\progam files\myproject\database\m
Nice? No, but at least something I can live with (as I know how my product is installed). So crystal ignores all the connectInfo somehow if you call PrintToPrinter (or ExportTo...).