Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1698
  • Last Modified:

.net crystal report change datasource

How to change datasource for a crystal report between databases also pass login and password
0
tnasca
Asked:
tnasca
  • 3
  • 2
  • 2
  • +1
1 Solution
 
tnascaAuthor Commented:
How to change datasouece for a crystal report between databases also pass login and password
0
 
tnascaAuthor Commented:
How to change datasouece for a crystal report between databases also pass login and password
0
 
James MurrellProduct SpecialistCommented:
can you post your dtasource
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
mlmccCommented:
0
 
tnascaAuthor Commented:
Here is the final code:
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

public partial class Members_Reports_cr : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ReportDocument crReportDocument = new ReportDocument();
        crReportDocument.Load(@"C:\Sites\Tony\ST\ST_Web\Members\Reports\Entire.rpt");        
        Database crDatabase;
        Tables crTables;
        CrystalDecisions.CrystalReports.Engine.Table crTable;
        TableLogOnInfo crTableLogOnInfo;
        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        crConnectionInfo.ServerName = "DNSERVER";
        crConnectionInfo.DatabaseName = "ST";
        crConnectionInfo.UserID = "xx";
        crConnectionInfo.Password = "yy";
        crDatabase = crReportDocument.Database;
        crTables = crDatabase.Tables;
        for (int i = 0; i < crTables.Count; i++)
            {
            crTable = crTables [i];
            crTableLogOnInfo = crTable.LogOnInfo;
            crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
            crTable.ApplyLogOnInfo(crTableLogOnInfo);
            //If your DatabaseName is changing at runtime, specify
            //the table location. For example, when you are reporting
            //off of a Northwind database on SQL server
            //you should have the following line of code:
            crTable.Location = "" +
                crTable.Location.Substring(crTable.Location.LastIndexOf
                (".") + 1);
            }        
       CrystalReportViewer1.ReportSource = crReportDocument;
    }
}
0
 
DeonMCommented:
Im using VS 2008 Pro with its bundled CR tool and i am sitting with the same problem. I tried the solution and i receive the following error:
Logon failed.
Details: ADO Error Code: 0x
Source: Microsoft OLE DB Provider for SQL Server
Description: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
SQL State: 08001
Native Error:

I receive this error on the following row:
for (int i = 0; i < crTables.Count; i++)
with the "i++" highlighted as the problem

Any help would be greatly appreciated.
0
 
mlmccCommented:
DeonM - Generally it is a good idea to ask your own question.  Only the asker and a limited number of experts will see this question.

mlmcc
0
 
DeonMCommented:
I understand that, however I do have my own question but its not being addressed to. Been waiting for days for any replies :/
So i don't know what to do anymore.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

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