Solved

.net crystal report change datasource

Posted on 2008-06-14
9
1,692 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
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 100

Accepted Solution

by:
mlmcc earned 500 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 100

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how the fundamental information of how to create a table.

777 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