• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1172
  • Last Modified:

Set connection string in ASP .net (2002) for CR 8.5

Dear all,

does anyone of you know how to set connection string in ASP .net 2002 for CR 8.5?

Thanks
0
ultrafish
Asked:
ultrafish
  • 2
1 Solution
 
ultrafishAuthor Commented:
The situation is I am using asp .net VS 2002 and CR 8.5, in the report, I use file dsn to connect to the database which works properly when I simply view the report, but when I go to .NET, I cannot set the logon info properly, the following is my code, does anyone has anyidea?

ReportDocument rptDoc = new ReportDocument();
rptDoc.Load("C:\\report.rpt");
rptDoc.SetParameterValue("param1", "1");
rptDoc.SetParameterValue("param2", "2");
rptDoc.SetDatabaseLogon("username", "password", "server", "database");                  
crViewer.ReportSource = rptDoc;
rptDoc.Export();

I simply connect to the database....
thanks
0
 
ebolekCommented:
Use this code
Call SetConnection(rptdoc). It will solve your problems

internal static void SetConnection(ref ReportDocument report)
            {
                  try
                  {
                        CrystalDecisions.Shared.TableLogOnInfo MyLogonInfo;
                        foreach(CrystalDecisions.CrystalReports.Engine.Table MyTable in report.Database.Tables)
                        {    
                              MyLogonInfo = MyTable.LogOnInfo;
                              MyLogonInfo.ConnectionInfo.ServerName  = ServerName;
                              MyLogonInfo.ConnectionInfo.DatabaseName = DatabaseName;
                              MyLogonInfo.ConnectionInfo.UserID  = UserName;
                              MyLogonInfo.ConnectionInfo.Password = Password;                              
                              MyTable.Location = MyTable.Location.Substring(MyTable.Location.LastIndexOf(".")+1);
                              MyTable.ApplyLogOnInfo(MyLogonInfo);            
                        }                        
                  }
                  catch( Exception logonInfoException )
                  {
                        throw logonInfoException;
                  }
            }
0
 
ebolekCommented:
Glad to help

Regards
Emre
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now