Solved

.net crystal report change datasource

Posted on 2008-06-14
9
1,689 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
Comment Utility
How to change datasouece for a crystal report between databases also pass login and password
0
 

Author Comment

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

Expert Comment

by:James Murrell
Comment Utility
can you post your dtasource
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
Comment Utility
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Closing Comment

by:tnasca
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now