Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.net crystal report change datasource

Posted on 2008-06-14
9
Medium Priority
?
1,697 Views
Last Modified: 2010-04-21
How to change datasource for a crystal report between databases also pass login and password
0
Comment
Question by:tnasca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 

Author Comment

by:tnasca
ID: 21786425
How to change datasouece for a crystal report between databases also pass login and password
0
 

Author Comment

by:tnasca
ID: 21786427
How to change datasouece for a crystal report between databases also pass login and password
0
 
LVL 31

Expert Comment

by:James Murrell
ID: 21787957
can you post your dtasource
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 101

Accepted Solution

by:
mlmcc earned 2000 total points
ID: 21790256
0
 

Author Closing Comment

by:tnasca
ID: 31597258
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
 

Expert Comment

by:DeonM
ID: 22109691
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 22112113
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
 

Expert Comment

by:DeonM
ID: 22118119
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question